<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE NoImplicitPrelude
           , RecordWildCards
           , BangPatterns
           , NondecreasingIndentation
           , RankNTypes
  #-}</span><span>
</span><span id="line-8"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-unused-matches #-}</span><span>
</span><span id="line-9"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-name-shadowing #-}</span><span>
</span><span id="line-10"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-incomplete-uni-patterns #-}</span><span>
</span><span id="line-11"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-12"></span><span>
</span><span id="line-13"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Module      :  GHC.IO.Handle.Internals</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1994-2001</span><span>
</span><span id="line-17"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-18"></span><span class="hs-comment">--</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-21"></span><span class="hs-comment">-- Portability :  non-portable</span><span>
</span><span id="line-22"></span><span class="hs-comment">--</span><span>
</span><span id="line-23"></span><span class="hs-comment">-- This module defines the basic operations on I\/O \&quot;handles\&quot;.  All</span><span>
</span><span id="line-24"></span><span class="hs-comment">-- of the operations defined here are independent of the underlying</span><span>
</span><span id="line-25"></span><span class="hs-comment">-- device.</span><span>
</span><span id="line-26"></span><span class="hs-comment">--</span><span>
</span><span id="line-27"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Internals</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-30"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-identifier">withHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle%27"><span class="hs-identifier">withHandle'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle_"><span class="hs-identifier">withHandle_</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle__%27"><span class="hs-identifier">withHandle__'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier">withHandle_'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withAllHandles__"><span class="hs-identifier">withAllHandles__</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-32"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier">wantWritableHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantReadableHandle"><span class="hs-identifier">wantReadableHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier">wantReadableHandle_</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-33"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantSeekableHandle"><span class="hs-identifier">wantSeekableHandle</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-34"></span><span>
</span><span id="line-35"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier">mkHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkFileHandle"><span class="hs-identifier">mkFileHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkDuplexHandle"><span class="hs-identifier">mkDuplexHandle</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-36"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#openTextEncoding"><span class="hs-identifier">openTextEncoding</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#closeTextCodecs"><span class="hs-identifier">closeTextCodecs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#initBufferState"><span class="hs-identifier">initBufferState</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-37"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#dEFAULT_CHAR_BUFFER_SIZE"><span class="hs-identifier">dEFAULT_CHAR_BUFFER_SIZE</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushBuffer"><span class="hs-identifier">flushBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier">flushWriteBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier">flushCharReadBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-40"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushCharBuffer"><span class="hs-identifier">flushCharBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushByteReadBuffer"><span class="hs-identifier">flushByteReadBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier">flushByteWriteBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-41"></span><span>
</span><span id="line-42"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier">readTextDevice</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier">writeCharBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#readTextDeviceNonBlocking"><span class="hs-identifier">readTextDeviceNonBlocking</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-43"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#decodeByteBuf"><span class="hs-identifier">decodeByteBuf</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-44"></span><span>
</span><span id="line-45"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#augmentIOError"><span class="hs-identifier">augmentIOError</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-46"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_closedHandle"><span class="hs-identifier">ioe_closedHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_semiclosedHandle"><span class="hs-identifier">ioe_semiclosedHandle</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-47"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier">ioe_EOF</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_notReadable"><span class="hs-identifier">ioe_notReadable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_notWritable"><span class="hs-identifier">ioe_notWritable</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-48"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_finalizedHandle"><span class="hs-identifier">ioe_finalizedHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_bufsiz"><span class="hs-identifier">ioe_bufsiz</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-49"></span><span>
</span><span id="line-50"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#hClose_help"><span class="hs-identifier">hClose_help</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#hLookAhead_"><span class="hs-identifier">hLookAhead_</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#HandleFinalizer"><span class="hs-identifier">HandleFinalizer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#handleFinalizer"><span class="hs-identifier">handleFinalizer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier">debugIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#traceIO"><span class="hs-identifier">traceIO</span></a></span><span>
</span><span id="line-55"></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-58"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html"><span class="hs-identifier">GHC.IO.IOMode</span></a></span><span>
</span><span id="line-59"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.html"><span class="hs-identifier">GHC.IO.Encoding</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Encoding</span></span><span>
</span><span id="line-60"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html"><span class="hs-identifier">GHC.IO.Encoding.Types</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier">CodeBuffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-61"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html"><span class="hs-identifier">GHC.IO.Handle.Types</span></a></span><span>
</span><span id="line-62"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html"><span class="hs-identifier">GHC.IO.Buffer</span></a></span><span>
</span><span id="line-63"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html"><span class="hs-identifier">GHC.IO.BufferedIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.BufferedIO.html#BufferedIO"><span class="hs-identifier">BufferedIO</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-64"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-65"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Device.html#IODevice"><span class="hs-identifier">IODevice</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier">RawIO</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#SeekMode"><span class="hs-identifier">SeekMode</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-66"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.SubSystem.html"><span class="hs-identifier">GHC.IO.SubSystem</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.SubSystem.html#%3C%21%3E"><span class="hs-operator">(&lt;!&gt;)</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.SubSystem.html#isWindowsNativeIO"><span class="hs-identifier">isWindowsNativeIO</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-67"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IODevice</span></span><span>
</span><span id="line-68"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html"><span class="hs-identifier">GHC.IO.BufferedIO</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Buffered</span></span><span>
</span><span id="line-69"></span><span>
</span><span id="line-70"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Conc.Sync.html"><span class="hs-identifier">GHC.Conc.Sync</span></a></span><span>
</span><span id="line-71"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-72"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-73"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Exception.html"><span class="hs-identifier">GHC.Exception</span></a></span><span>
</span><span id="line-74"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>          </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Num.html#Num"><span class="hs-identifier">Num</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-75"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-76"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IORef.html"><span class="hs-identifier">GHC.IORef</span></a></span><span>
</span><span id="line-77"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.MVar.html"><span class="hs-identifier">GHC.MVar</span></a></span><span>
</span><span id="line-78"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Typeable.html"><span class="hs-identifier">Data.Typeable</span></a></span><span>
</span><span id="line-79"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-80"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-81"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.Posix.Internals.html"><span class="hs-identifier">System.Posix.Internals</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="System.Posix.Internals.html#FD"><span class="hs-identifier">FD</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-82"></span><span>
</span><span id="line-83"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.html"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-84"></span><span>
</span><span id="line-85"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#c_DEBUG_DUMP"><span class="hs-identifier hs-type">c_DEBUG_DUMP</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-86"></span><span id="c_DEBUG_DUMP"><span class="annot"><span class="annottext">c_DEBUG_DUMP :: Bool
</span><a href="GHC.IO.Handle.Internals.html#c_DEBUG_DUMP"><span class="hs-identifier hs-var hs-var">c_DEBUG_DUMP</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-87"></span><span>
</span><span id="line-88"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-89"></span><span class="hs-comment">-- Creating a new handle</span><span>
</span><span id="line-90"></span><span>
</span><span id="line-91"></span><span class="hs-keyword">type</span><span> </span><span id="HandleFinalizer"><span class="annot"><a href="GHC.IO.Handle.Internals.html#HandleFinalizer"><span class="hs-identifier hs-var">HandleFinalizer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-92"></span><span>
</span><span id="line-93"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#newFileHandle"><span class="hs-identifier hs-type">newFileHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#HandleFinalizer"><span class="hs-identifier hs-type">HandleFinalizer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>
</span><span id="line-94"></span><span id="newFileHandle"><span class="annot"><span class="annottext">newFileHandle :: FilePath -&gt; Maybe HandleFinalizer -&gt; Handle__ -&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#newFileHandle"><span class="hs-identifier hs-var hs-var">newFileHandle</span></a></span></span><span> </span><span id="local-6989586621679548529"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548529"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679548528"><span class="annot"><span class="annottext">Maybe HandleFinalizer
</span><a href="#local-6989586621679548528"><span class="hs-identifier hs-var">mb_finalizer</span></a></span></span><span> </span><span id="local-6989586621679548527"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548527"><span class="hs-identifier hs-var">hc</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-95"></span><span>  </span><span id="local-6989586621679548526"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548526"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (MVar Handle__)
forall a. a -&gt; IO (MVar a)
</span><a href="GHC.MVar.html#newMVar"><span class="hs-identifier hs-var">newMVar</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548527"><span class="hs-identifier hs-var">hc</span></a></span><span>
</span><span id="line-96"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe HandleFinalizer
</span><a href="#local-6989586621679548528"><span class="hs-identifier hs-var">mb_finalizer</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-97"></span><span>    </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679548524"><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="#local-6989586621679548524"><span class="hs-identifier hs-var">finalizer</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(FilePath -&gt; IO ()) -&gt; FilePath -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;Registering finalizer: &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath
forall a. Show a =&gt; a -&gt; FilePath
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548529"><span class="hs-identifier hs-var">filepath</span></a></span><span>
</span><span id="line-98"></span><span>                         </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; IO () -&gt; IO ()
forall a. MVar a -&gt; IO () -&gt; IO ()
</span><a href="GHC.MVar.html#addMVarFinalizer"><span class="hs-identifier hs-var">addMVarFinalizer</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548526"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="#local-6989586621679548524"><span class="hs-identifier hs-var">finalizer</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548529"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548526"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-99"></span><span>    </span><span class="annot"><span class="annottext">Maybe HandleFinalizer
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(FilePath -&gt; IO ()) -&gt; FilePath -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;No finalizer: &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath
forall a. Show a =&gt; a -&gt; FilePath
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548529"><span class="hs-identifier hs-var">filepath</span></a></span><span>
</span><span id="line-100"></span><span>                         </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-101"></span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; IO Handle
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; MVar Handle__ -&gt; Handle
</span><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-var">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548529"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548526"><span class="hs-identifier hs-var">m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-102"></span><span>
</span><span id="line-103"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-104"></span><span class="hs-comment">-- Working with Handles</span><span>
</span><span id="line-105"></span><span>
</span><span id="line-106"></span><span class="hs-comment">{-
In the concurrent world, handles are locked during use.  This is done
by wrapping an MVar around the handle which acts as a mutex over
operations on the handle.

To avoid races, we use the following bracketing operations.  The idea
is to obtain the lock, do some operation and replace the lock again,
whether the operation succeeded or failed.  We also want to handle the
case where the thread receives an exception while processing the IO
operation: in these cases we also want to relinquish the lock.

There are three versions of @withHandle@: corresponding to the three
possible combinations of:

        - the operation may side-effect the handle
        - the operation may return a result

If the operation generates an error or an exception is raised, the
original handle is always replaced.
-}</span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-pragma hs-type">withHandle</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-128"></span><span id="local-6989586621679548814"><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-identifier hs-type">withHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621679548814"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548814"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-129"></span><span id="withHandle"><span class="annot"><span class="annottext">withHandle :: forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-identifier hs-var hs-var">withHandle</span></a></span></span><span> </span><span id="local-6989586621679548520"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548520"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548519"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548519"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548518"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548518"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>     </span><span id="local-6989586621679548517"><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548517"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
forall a.
FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle%27"><span class="hs-identifier hs-var">withHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548520"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548519"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548518"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548517"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-130"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-identifier hs-var">withHandle</span></a></span><span> </span><span id="local-6989586621679548516"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548516"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548515"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548515"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548513"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548513"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548512"><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548512"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
forall a.
FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle%27"><span class="hs-identifier hs-var">withHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548516"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548515"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548513"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548512"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-131"></span><span>
</span><span id="line-132"></span><span id="local-6989586621679548812"><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle%27"><span class="hs-identifier hs-type">withHandle'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span>
</span><span id="line-133"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621679548812"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548812"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-134"></span><span id="withHandle%27"><span class="annot"><span class="annottext">withHandle' :: forall a.
FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle%27"><span class="hs-identifier hs-var hs-var">withHandle'</span></a></span></span><span> </span><span id="local-6989586621679548507"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548507"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548506"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548506"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548505"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548505"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679548504"><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548504"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-135"></span><span> </span><span class="annot"><span class="annottext">IO a -&gt; IO a
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span> </span><span class="annot"><span class="annottext">(IO a -&gt; IO a) -&gt; IO a -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-136"></span><span>   </span><span class="hs-special">(</span><span id="local-6989586621679548502"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548502"><span class="hs-identifier hs-var">h'</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679548501"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679548501"><span class="hs-identifier hs-var">v</span></a></span></span><span class="hs-special">)</span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; MVar Handle__
-&gt; IO (Handle__, a)
forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; MVar Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#do_operation"><span class="hs-identifier hs-var">do_operation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548507"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548506"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548504"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548505"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-137"></span><span>   </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Types.html#checkHandleInvariants"><span class="hs-identifier hs-var">checkHandleInvariants</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548502"><span class="hs-identifier hs-var">h'</span></a></span><span>
</span><span id="line-138"></span><span>   </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; Handle__ -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548505"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548502"><span class="hs-identifier hs-var">h'</span></a></span><span>
</span><span id="line-139"></span><span>   </span><span class="annot"><span class="annottext">a -&gt; IO a
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679548501"><span class="hs-identifier hs-var">v</span></a></span><span>
</span><span id="line-140"></span><span>
</span><span id="line-141"></span><span class="hs-pragma">{-# INLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle_"><span class="hs-pragma hs-type">withHandle_</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-142"></span><span id="local-6989586621679548807"><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle_"><span class="hs-identifier hs-type">withHandle_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548807"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548807"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-143"></span><span id="withHandle_"><span class="annot"><span class="annottext">withHandle_ :: forall a. FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_"><span class="hs-identifier hs-var hs-var">withHandle_</span></a></span></span><span> </span><span id="local-6989586621679548497"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548497"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548496"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548496"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548495"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548495"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>     </span><span id="local-6989586621679548494"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548494"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-var">withHandle_'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548497"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548496"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548495"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548494"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-144"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle_"><span class="hs-identifier hs-var">withHandle_</span></a></span><span> </span><span id="local-6989586621679548493"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548493"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548492"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548492"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548491"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548491"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548490"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548490"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-var">withHandle_'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548493"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548492"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548491"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548490"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-145"></span><span>
</span><span id="line-146"></span><span id="local-6989586621679548805"><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-type">withHandle_'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548805"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548805"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-147"></span><span id="withHandle_%27"><span class="annot"><span class="annottext">withHandle_' :: forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-var hs-var">withHandle_'</span></a></span></span><span> </span><span id="local-6989586621679548487"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548487"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548486"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548486"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548485"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548485"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679548484"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548484"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
forall a.
FilePath
-&gt; Handle
-&gt; MVar Handle__
-&gt; (Handle__ -&gt; IO (Handle__, a))
-&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle%27"><span class="hs-identifier hs-var">withHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548487"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548486"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548485"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO (Handle__, a)) -&gt; IO a)
-&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679548483"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548483"><span class="hs-identifier hs-var">h_</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-148"></span><span>                              </span><span id="local-6989586621679548482"><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679548482"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548484"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548483"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-149"></span><span>                              </span><span class="annot"><span class="annottext">(Handle__, a) -&gt; IO (Handle__, a)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548483"><span class="hs-identifier hs-var">h_</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">a
</span><a href="#local-6989586621679548482"><span class="hs-identifier hs-var">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-150"></span><span>
</span><span id="line-151"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withAllHandles__"><span class="hs-identifier hs-type">withAllHandles__</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-152"></span><span id="withAllHandles__"><span class="annot"><span class="annottext">withAllHandles__ :: FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO Handle__) -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#withAllHandles__"><span class="hs-identifier hs-var hs-var">withAllHandles__</span></a></span></span><span> </span><span id="local-6989586621679548481"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548481"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548480"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548480"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548479"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548479"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>     </span><span id="local-6989586621679548478"><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548478"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO Handle__) -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#withHandle__%27"><span class="hs-identifier hs-var">withHandle__'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548481"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548480"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548479"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548478"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-153"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withAllHandles__"><span class="hs-identifier hs-var">withAllHandles__</span></a></span><span> </span><span id="local-6989586621679548477"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548477"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548476"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548476"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548475"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548475"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span id="local-6989586621679548474"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548474"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548473"><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548473"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-154"></span><span>  </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO Handle__) -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#withHandle__%27"><span class="hs-identifier hs-var">withHandle__'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548477"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548476"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548475"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548473"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-155"></span><span>  </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO Handle__) -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#withHandle__%27"><span class="hs-identifier hs-var">withHandle__'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548477"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548476"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548474"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548473"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-156"></span><span>
</span><span id="line-157"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#withHandle__%27"><span class="hs-identifier hs-type">withHandle__'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-158"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-159"></span><span id="withHandle__%27"><span class="annot"><span class="annottext">withHandle__' :: FilePath
-&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO Handle__) -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#withHandle__%27"><span class="hs-identifier hs-var hs-var">withHandle__'</span></a></span></span><span> </span><span id="local-6989586621679548472"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548472"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548471"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548471"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548470"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548470"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679548469"><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548469"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-160"></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO ()
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.html#mask_"><span class="hs-identifier hs-var">mask_</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-161"></span><span>   </span><span id="local-6989586621679548468"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548468"><span class="hs-identifier hs-var">h'</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FilePath
-&gt; Handle
-&gt; (Handle__ -&gt; IO Handle__)
-&gt; MVar Handle__
-&gt; IO Handle__
forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; MVar Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#do_operation"><span class="hs-identifier hs-var">do_operation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548472"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548471"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO Handle__
</span><a href="#local-6989586621679548469"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548470"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-162"></span><span>   </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Types.html#checkHandleInvariants"><span class="hs-identifier hs-var">checkHandleInvariants</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548468"><span class="hs-identifier hs-var">h'</span></a></span><span>
</span><span id="line-163"></span><span>   </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; Handle__ -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548470"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548468"><span class="hs-identifier hs-var">h'</span></a></span><span>
</span><span id="line-164"></span><span>   </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-165"></span><span>
</span><span id="line-166"></span><span id="local-6989586621679548809"><span class="annot"><a href="GHC.IO.Handle.Internals.html#do_operation"><span class="hs-identifier hs-type">do_operation</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548809"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548809"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-167"></span><span id="do_operation"><span class="annot"><span class="annottext">do_operation :: forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; MVar Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#do_operation"><span class="hs-identifier hs-var hs-var">do_operation</span></a></span></span><span> </span><span id="local-6989586621679548464"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548464"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548463"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548463"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548462"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548462"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span id="local-6989586621679548461"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548461"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-168"></span><span>  </span><span id="local-6989586621679548460"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548460"><span class="hs-identifier hs-var">h_</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; IO Handle__
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548461"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-169"></span><span>  </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Types.html#checkHandleInvariants"><span class="hs-identifier hs-var">checkHandleInvariants</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548460"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-170"></span><span>  </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548462"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548460"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">IO a -&gt; (SomeException -&gt; IO a) -&gt; IO a
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-operator hs-var">`catchException`</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; SomeException -&gt; IO a
</span><a href="#local-6989586621679548457"><span class="hs-identifier hs-var">handler</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548460"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-171"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-172"></span><span>    </span><span id="local-6989586621679548457"><span class="annot"><span class="annottext">handler :: Handle__ -&gt; SomeException -&gt; IO a
</span><a href="#local-6989586621679548457"><span class="hs-identifier hs-var hs-var">handler</span></a></span></span><span> </span><span id="local-6989586621679548448"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548448"><span class="hs-identifier hs-var">h_</span></a></span></span><span> </span><span id="local-6989586621679548447"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679548447"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-173"></span><span>      </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; Handle__ -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548461"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548448"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-174"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-175"></span><span>        </span><span class="annot"><span class="annottext">()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679548446"><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679548446"><span class="hs-identifier hs-var">ioe</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe IOException
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679548447"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-176"></span><span>            </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOException -&gt; FilePath -&gt; Handle -&gt; IOException
</span><a href="GHC.IO.Handle.Internals.html#augmentIOError"><span class="hs-identifier hs-var">augmentIOError</span></a></span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679548446"><span class="hs-identifier hs-var">ioe</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548464"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548463"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-177"></span><span>        </span><span class="annot"><span class="annottext">()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679548443"><span class="annot"><span class="annottext">SomeAsyncException
</span><a href="#local-6989586621679548443"><span class="hs-identifier hs-var">async_ex</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe SomeAsyncException
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679548447"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- see Note [async]</span><span>
</span><span id="line-178"></span><span>            </span><span class="hs-keyword">let</span><span> </span><span class="annot"><span class="annottext">SomeAsyncException
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SomeAsyncException
</span><a href="#local-6989586621679548443"><span class="hs-identifier hs-var">async_ex</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#SomeAsyncException"><span class="hs-identifier hs-type">SomeAsyncException</span></a></span><span>
</span><span id="line-179"></span><span>            </span><span id="local-6989586621679548442"><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679548442"><span class="hs-identifier hs-var">t</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO ThreadId
</span><a href="GHC.Conc.Sync.html#myThreadId"><span class="hs-identifier hs-var">myThreadId</span></a></span><span>
</span><span id="line-180"></span><span>            </span><span class="annot"><span class="annottext">ThreadId -&gt; SomeException -&gt; IO ()
forall e. Exception e =&gt; ThreadId -&gt; e -&gt; IO ()
</span><a href="GHC.Conc.Sync.html#throwTo"><span class="hs-identifier hs-var">throwTo</span></a></span><span> </span><span class="annot"><span class="annottext">ThreadId
</span><a href="#local-6989586621679548442"><span class="hs-identifier hs-var">t</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679548447"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-181"></span><span>            </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; MVar Handle__ -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; MVar Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#do_operation"><span class="hs-identifier hs-var">do_operation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548464"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548463"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548462"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548461"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-182"></span><span>        </span><span id="local-6989586621679548439"><span class="annot"><span class="annottext">()
</span><a href="#local-6989586621679548439"><span class="hs-identifier hs-var">_otherwise</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-183"></span><span>            </span><span class="annot"><span class="annottext">SomeException -&gt; IO a
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679548447"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-184"></span><span>
</span><span id="line-185"></span><span class="hs-comment">-- Note [async]</span><span>
</span><span id="line-186"></span><span class="hs-comment">--</span><span>
</span><span id="line-187"></span><span class="hs-comment">-- If an asynchronous exception is raised during an I/O operation,</span><span>
</span><span id="line-188"></span><span class="hs-comment">-- normally it is fine to just re-throw the exception synchronously.</span><span>
</span><span id="line-189"></span><span class="hs-comment">-- However, if we are inside an unsafePerformIO or an</span><span>
</span><span id="line-190"></span><span class="hs-comment">-- unsafeInterleaveIO, this would replace the enclosing thunk with the</span><span>
</span><span id="line-191"></span><span class="hs-comment">-- exception raised, which is wrong (#3997).  We have to release the</span><span>
</span><span id="line-192"></span><span class="hs-comment">-- lock on the Handle, but what do we replace the thunk with?  What</span><span>
</span><span id="line-193"></span><span class="hs-comment">-- should happen when the thunk is subsequently demanded again?</span><span>
</span><span id="line-194"></span><span class="hs-comment">--</span><span>
</span><span id="line-195"></span><span class="hs-comment">-- The only sensible choice we have is to re-do the IO operation on</span><span>
</span><span id="line-196"></span><span class="hs-comment">-- resumption, but then we have to be careful in the IO library that</span><span>
</span><span id="line-197"></span><span class="hs-comment">-- this is always safe to do.  In particular we should</span><span>
</span><span id="line-198"></span><span class="hs-comment">--</span><span>
</span><span id="line-199"></span><span class="hs-comment">--    never perform any side-effects before an interruptible operation</span><span>
</span><span id="line-200"></span><span class="hs-comment">--</span><span>
</span><span id="line-201"></span><span class="hs-comment">-- because the interruptible operation may raise an asynchronous</span><span>
</span><span id="line-202"></span><span class="hs-comment">-- exception, which may cause the operation and its side effects to be</span><span>
</span><span id="line-203"></span><span class="hs-comment">-- subsequently performed again.</span><span>
</span><span id="line-204"></span><span class="hs-comment">--</span><span>
</span><span id="line-205"></span><span class="hs-comment">-- Re-doing the IO operation is achieved by:</span><span>
</span><span id="line-206"></span><span class="hs-comment">--   - using throwTo to re-throw the asynchronous exception asynchronously</span><span>
</span><span id="line-207"></span><span class="hs-comment">--     in the current thread</span><span>
</span><span id="line-208"></span><span class="hs-comment">--   - on resumption, it will be as if throwTo returns.  In that case, we</span><span>
</span><span id="line-209"></span><span class="hs-comment">--     recursively invoke the original operation (see do_operation above).</span><span>
</span><span id="line-210"></span><span class="hs-comment">--</span><span>
</span><span id="line-211"></span><span class="hs-comment">-- Interruptible operations in the I/O library are:</span><span>
</span><span id="line-212"></span><span class="hs-comment">--    - threadWaitRead/threadWaitWrite</span><span>
</span><span id="line-213"></span><span class="hs-comment">--    - fillReadBuffer/flushWriteBuffer</span><span>
</span><span id="line-214"></span><span class="hs-comment">--    - readTextDevice/writeTextDevice</span><span>
</span><span id="line-215"></span><span>
</span><span id="line-216"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#augmentIOError"><span class="hs-identifier hs-type">augmentIOError</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#IOException"><span class="hs-identifier hs-type">IOException</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html#IOException"><span class="hs-identifier hs-type">IOException</span></a></span><span>
</span><span id="line-217"></span><span id="augmentIOError"><span class="annot"><span class="annottext">augmentIOError :: IOException -&gt; FilePath -&gt; Handle -&gt; IOException
</span><a href="GHC.IO.Handle.Internals.html#augmentIOError"><span class="hs-identifier hs-var hs-var">augmentIOError</span></a></span></span><span> </span><span id="local-6989586621679548437"><span class="annot"><span class="annottext">ioe :: IOException
</span><a href="#local-6989586621679548437"><span class="hs-identifier hs-var">ioe</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-type">IOError</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ioe_filename :: IOException -&gt; Maybe FilePath
</span><a href="GHC.IO.Exception.html#ioe_filename"><span class="hs-identifier hs-var">ioe_filename</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621679548434"><span class="annot"><span class="annottext">Maybe FilePath
</span><a href="#local-6989586621679548434"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span id="local-6989586621679548433"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548433"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548432"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548432"><span class="hs-identifier hs-var">h</span></a></span></span><span>
</span><span id="line-218"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException
</span><a href="#local-6989586621679548437"><span class="hs-identifier hs-var">ioe</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ioe_handle :: Maybe Handle
</span><a href="GHC.IO.Exception.html#ioe_handle"><span class="hs-identifier hs-var">ioe_handle</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548432"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ioe_location :: FilePath
</span><a href="GHC.IO.Exception.html#ioe_location"><span class="hs-identifier hs-var">ioe_location</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548433"><span class="hs-identifier hs-var">fun</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ioe_filename :: Maybe FilePath
</span><a href="GHC.IO.Exception.html#ioe_filename"><span class="hs-identifier hs-var">ioe_filename</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
</span><a href="#local-6989586621679548429"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-219"></span><span>  </span><span class="hs-keyword">where</span><span> </span><span id="local-6989586621679548429"><span class="annot"><span class="annottext">filepath :: Maybe FilePath
</span><a href="#local-6989586621679548429"><span class="hs-identifier hs-var hs-var">filepath</span></a></span></span><span>
</span><span id="line-220"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
</span><a href="#local-6989586621679548434"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
</span><a href="#local-6989586621679548434"><span class="hs-identifier hs-var">fp</span></a></span><span>
</span><span id="line-221"></span><span>          </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548432"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-222"></span><span>                          </span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span id="local-6989586621679548428"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548428"><span class="hs-identifier hs-var">path</span></a></span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Maybe FilePath
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548428"><span class="hs-identifier hs-var">path</span></a></span><span>
</span><span id="line-223"></span><span>                          </span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span id="local-6989586621679548427"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548427"><span class="hs-identifier hs-var">path</span></a></span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Maybe FilePath
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548427"><span class="hs-identifier hs-var">path</span></a></span><span>
</span><span id="line-224"></span><span>
</span><span id="line-225"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-226"></span><span class="hs-comment">-- Wrapper for write operations.</span><span>
</span><span id="line-227"></span><span>
</span><span id="line-228"></span><span class="hs-comment">-- If we already have a writeable handle just run the action.</span><span>
</span><span id="line-229"></span><span class="hs-comment">-- If we have a read only handle we throw an exception.</span><span>
</span><span id="line-230"></span><span class="hs-comment">-- If we have a read/write handle in read mode we:</span><span>
</span><span id="line-231"></span><span class="hs-comment">-- * Seek to the unread (from the users PoV) position and</span><span>
</span><span id="line-232"></span><span class="hs-comment">--   change the handles buffer to a write buffer.</span><span>
</span><span id="line-233"></span><span id="local-6989586621679548426"><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-type">wantWritableHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548426"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548426"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-234"></span><span id="wantWritableHandle"><span class="annot"><span class="annottext">wantWritableHandle :: forall a. FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var hs-var">wantWritableHandle</span></a></span></span><span> </span><span id="local-6989586621679548425"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548425"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548424"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548424"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548423"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548423"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548422"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548422"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-235"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle%27"><span class="hs-identifier hs-var">wantWritableHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548425"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548424"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548423"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548422"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-236"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var">wantWritableHandle</span></a></span><span> </span><span id="local-6989586621679548420"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548420"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548419"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548419"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548418"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548418"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548417"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548417"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-237"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle%27"><span class="hs-identifier hs-var">wantWritableHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548420"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548419"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548418"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548417"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-238"></span><span>    </span><span class="hs-comment">-- we know it's not a ReadHandle or ReadWriteHandle, but we have to</span><span>
</span><span id="line-239"></span><span>    </span><span class="hs-comment">-- check for ClosedHandle/SemiClosedHandle. (#4808)</span><span>
</span><span id="line-240"></span><span>
</span><span id="line-241"></span><span id="local-6989586621679548416"><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantWritableHandle%27"><span class="hs-identifier hs-type">wantWritableHandle'</span></a></span><span>
</span><span id="line-242"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span>
</span><span id="line-243"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548416"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548416"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-244"></span><span id="wantWritableHandle%27"><span class="annot"><span class="annottext">wantWritableHandle' :: forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle%27"><span class="hs-identifier hs-var hs-var">wantWritableHandle'</span></a></span></span><span> </span><span id="local-6989586621679548415"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548415"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548414"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548414"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548413"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548413"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679548412"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548412"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-245"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-var">withHandle_'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548415"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548414"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548413"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkWritableHandle"><span class="hs-identifier hs-var">checkWritableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548412"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-246"></span><span>
</span><span id="line-247"></span><span id="local-6989586621679548789"><span class="annot"><a href="GHC.IO.Handle.Internals.html#checkWritableHandle"><span class="hs-identifier hs-type">checkWritableHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548789"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548789"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-248"></span><span id="checkWritableHandle"><span class="annot"><span class="annottext">checkWritableHandle :: forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkWritableHandle"><span class="hs-identifier hs-var hs-var">checkWritableHandle</span></a></span></span><span> </span><span id="local-6989586621679548410"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548410"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span id="local-6989586621679548409"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548409"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548380"><span id="local-6989586621679548381"><span id="local-6989586621679548382"><span id="local-6989586621679548383"><span id="local-6989586621679548384"><span id="local-6989586621679548385"><span id="local-6989586621679548386"><span id="local-6989586621679548387"><span id="local-6989586621679548388"><span id="local-6989586621679548389"><span id="local-6989586621679548390"><span id="local-6989586621679548391"><span id="local-6989586621679548392"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-249"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679548391"><span class="hs-identifier hs-var">haType</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-250"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_closedHandle"><span class="hs-identifier hs-var">ioe_closedHandle</span></a></span><span>
</span><span id="line-251"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#SemiClosedHandle"><span class="hs-identifier hs-var">SemiClosedHandle</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_semiclosedHandle"><span class="hs-identifier hs-var">ioe_semiclosedHandle</span></a></span><span>
</span><span id="line-252"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadHandle"><span class="hs-identifier hs-var">ReadHandle</span></a></span><span>           </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notWritable"><span class="hs-identifier hs-var">ioe_notWritable</span></a></span><span>
</span><span id="line-253"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadWriteHandle"><span class="hs-identifier hs-var">ReadWriteHandle</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-254"></span><span>        </span><span id="local-6989586621679548362"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548362"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548387"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-255"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier hs-var">isWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548362"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-256"></span><span>           </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var">flushCharReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548409"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-257"></span><span>           </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteReadBuffer"><span class="hs-identifier hs-var">flushByteReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548409"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-258"></span><span>           </span><span id="local-6989586621679548357"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548357"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548387"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-259"></span><span>           </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548387"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548357"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-260"></span><span>           </span><span id="local-6989586621679548353"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548353"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548390"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-261"></span><span>           </span><span id="local-6989586621679548352"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548352"><span class="hs-identifier hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#emptyWriteBuffer"><span class="hs-identifier hs-var">Buffered.emptyWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548392"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548353"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-262"></span><span>           </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548390"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548352"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-263"></span><span>        </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548410"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548409"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-264"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#AppendHandle"><span class="hs-identifier hs-var">AppendHandle</span></a></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548410"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548409"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-265"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#WriteHandle"><span class="hs-identifier hs-var">WriteHandle</span></a></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548410"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548409"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-266"></span><span>
</span><span id="line-267"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-268"></span><span class="hs-comment">-- Wrapper for read operations.</span><span>
</span><span id="line-269"></span><span>
</span><span id="line-270"></span><span id="local-6989586621679548348"><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantReadableHandle"><span class="hs-identifier hs-type">wantReadableHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621679548348"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548348"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-271"></span><span id="wantReadableHandle"><span class="annot"><span class="annottext">wantReadableHandle :: forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle"><span class="hs-identifier hs-var hs-var">wantReadableHandle</span></a></span></span><span> </span><span id="local-6989586621679548347"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548347"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548346"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548346"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548345"><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548345"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-272"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-identifier hs-var">withHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548347"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548346"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Handle__ -&gt; IO (Handle__, a)) -&gt; Handle__ -&gt; IO (Handle__, a)
forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkReadableHandle"><span class="hs-identifier hs-var">checkReadableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, a)
</span><a href="#local-6989586621679548345"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-273"></span><span>
</span><span id="line-274"></span><span id="local-6989586621679548343"><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-type">wantReadableHandle_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548343"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548343"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-275"></span><span id="wantReadableHandle_"><span class="annot"><span class="annottext">wantReadableHandle_ :: forall a. FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var hs-var">wantReadableHandle_</span></a></span></span><span> </span><span id="local-6989586621679548342"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548342"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548341"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548341"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span>  </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548340"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548340"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span>   </span><span id="local-6989586621679548339"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548339"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-276"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle%27"><span class="hs-identifier hs-var">wantReadableHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548342"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548341"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548340"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548339"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-277"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span id="local-6989586621679548337"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548337"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548336"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548336"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548335"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548335"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548334"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548334"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-278"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle%27"><span class="hs-identifier hs-var">wantReadableHandle'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548337"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548336"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548335"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548334"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-279"></span><span>    </span><span class="hs-comment">-- we know it's not a WriteHandle or ReadWriteHandle, but we have to</span><span>
</span><span id="line-280"></span><span>    </span><span class="hs-comment">-- check for ClosedHandle/SemiClosedHandle. (#4808)</span><span>
</span><span id="line-281"></span><span>
</span><span id="line-282"></span><span id="local-6989586621679548333"><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantReadableHandle%27"><span class="hs-identifier hs-type">wantReadableHandle'</span></a></span><span>
</span><span id="line-283"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span>
</span><span id="line-284"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548333"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548333"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-285"></span><span id="wantReadableHandle%27"><span class="annot"><span class="annottext">wantReadableHandle' :: forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle%27"><span class="hs-identifier hs-var hs-var">wantReadableHandle'</span></a></span></span><span> </span><span id="local-6989586621679548332"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548332"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548331"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548331"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679548330"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548330"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span id="local-6989586621679548329"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548329"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-286"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-var">withHandle_'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548332"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548331"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548330"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkReadableHandle"><span class="hs-identifier hs-var">checkReadableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548329"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-287"></span><span>
</span><span id="line-288"></span><span id="local-6989586621679548328"><span class="annot"><a href="GHC.IO.Handle.Internals.html#checkReadableHandle"><span class="hs-identifier hs-type">checkReadableHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548328"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548328"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-289"></span><span id="checkReadableHandle"><span class="annot"><span class="annottext">checkReadableHandle :: forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkReadableHandle"><span class="hs-identifier hs-var hs-var">checkReadableHandle</span></a></span></span><span> </span><span id="local-6989586621679548327"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548327"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span id="local-6989586621679548326"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548326"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548301"><span id="local-6989586621679548302"><span id="local-6989586621679548303"><span id="local-6989586621679548304"><span id="local-6989586621679548305"><span id="local-6989586621679548306"><span id="local-6989586621679548307"><span id="local-6989586621679548308"><span id="local-6989586621679548309"><span id="local-6989586621679548310"><span id="local-6989586621679548311"><span id="local-6989586621679548312"><span id="local-6989586621679548313"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548301"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-290"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679548312"><span class="hs-identifier hs-var">haType</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-291"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_closedHandle"><span class="hs-identifier hs-var">ioe_closedHandle</span></a></span><span>
</span><span id="line-292"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#SemiClosedHandle"><span class="hs-identifier hs-var">SemiClosedHandle</span></a></span><span>     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_semiclosedHandle"><span class="hs-identifier hs-var">ioe_semiclosedHandle</span></a></span><span>
</span><span id="line-293"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#AppendHandle"><span class="hs-identifier hs-var">AppendHandle</span></a></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notReadable"><span class="hs-identifier hs-var">ioe_notReadable</span></a></span><span>
</span><span id="line-294"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#WriteHandle"><span class="hs-identifier hs-var">WriteHandle</span></a></span><span>          </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notReadable"><span class="hs-identifier hs-var">ioe_notReadable</span></a></span><span>
</span><span id="line-295"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadWriteHandle"><span class="hs-identifier hs-var">ReadWriteHandle</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-296"></span><span>          </span><span class="hs-comment">-- a read/write handle and we want to read from it.  We must</span><span>
</span><span id="line-297"></span><span>          </span><span class="hs-comment">-- flush all buffered write data first.</span><span>
</span><span id="line-298"></span><span>          </span><span id="local-6989586621679548300"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548300"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548311"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-299"></span><span>          </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier hs-var">isWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548300"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-300"></span><span>             </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548300"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var">flushByteWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548326"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-301"></span><span>             </span><span id="local-6989586621679548298"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548298"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548308"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-302"></span><span>             </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548308"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548298"><span class="hs-identifier hs-var">cbuf'</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-303"></span><span>             </span><span id="local-6989586621679548296"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548296"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548311"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-304"></span><span>             </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548311"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548296"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-305"></span><span>          </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548327"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548326"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-306"></span><span>      </span><span id="local-6989586621679548295"><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679548295"><span class="hs-identifier hs-var">_other</span></a></span></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548327"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548326"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-307"></span><span>
</span><span id="line-308"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-309"></span><span class="hs-comment">-- Wrapper for seek operations.</span><span>
</span><span id="line-310"></span><span>
</span><span id="line-311"></span><span id="local-6989586621679548294"><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantSeekableHandle"><span class="hs-identifier hs-type">wantSeekableHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548294"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548294"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-312"></span><span id="wantSeekableHandle"><span class="annot"><span class="annottext">wantSeekableHandle :: forall a. FilePath -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantSeekableHandle"><span class="hs-identifier hs-var hs-var">wantSeekableHandle</span></a></span></span><span> </span><span id="local-6989586621679548293"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548293"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548292"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548292"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-type">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548291"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548291"><span class="hs-identifier hs-var">_act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-313"></span><span>  </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548292"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548293"><span class="hs-identifier hs-var">fun</span></a></span><span>
</span><span id="line-314"></span><span>                   </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is not seekable&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-315"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#wantSeekableHandle"><span class="hs-identifier hs-var">wantSeekableHandle</span></a></span><span> </span><span id="local-6989586621679548288"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548288"><span class="hs-identifier hs-var">fun</span></a></span></span><span> </span><span id="local-6989586621679548287"><span class="annot"><span class="annottext">h :: Handle
</span><a href="#local-6989586621679548287"><span class="hs-identifier hs-var">h</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679548286"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548286"><span class="hs-identifier hs-var">m</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679548285"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548285"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-316"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
forall a.
FilePath -&gt; Handle -&gt; MVar Handle__ -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle_%27"><span class="hs-identifier hs-var">withHandle_'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548288"><span class="hs-identifier hs-var">fun</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679548287"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548286"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkSeekableHandle"><span class="hs-identifier hs-var">checkSeekableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548285"><span class="hs-identifier hs-var">act</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-317"></span><span>
</span><span id="line-318"></span><span id="local-6989586621679548283"><span class="annot"><a href="GHC.IO.Handle.Internals.html#checkSeekableHandle"><span class="hs-identifier hs-type">checkSeekableHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548283"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548283"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-319"></span><span id="checkSeekableHandle"><span class="annot"><span class="annottext">checkSeekableHandle :: forall a. (Handle__ -&gt; IO a) -&gt; Handle__ -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#checkSeekableHandle"><span class="hs-identifier hs-var hs-var">checkSeekableHandle</span></a></span></span><span> </span><span id="local-6989586621679548282"><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548282"><span class="hs-identifier hs-var">act</span></a></span></span><span> </span><span id="local-6989586621679548281"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679548281"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">haDevice :: ()
</span><a href="GHC.IO.Handle.Types.html#haDevice"><span class="hs-identifier hs-var">haDevice</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679548274"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548274"><span class="hs-identifier hs-var">dev</span></a></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-320"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var hs-var">haType</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548281"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-321"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_closedHandle"><span class="hs-identifier hs-var">ioe_closedHandle</span></a></span><span>
</span><span id="line-322"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#SemiClosedHandle"><span class="hs-identifier hs-var">SemiClosedHandle</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_semiclosedHandle"><span class="hs-identifier hs-var">ioe_semiclosedHandle</span></a></span><span>
</span><span id="line-323"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#AppendHandle"><span class="hs-identifier hs-var">AppendHandle</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notSeekable"><span class="hs-identifier hs-var">ioe_notSeekable</span></a></span><span>
</span><span id="line-324"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679548272"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679548272"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; IO Bool
forall a. IODevice a =&gt; a -&gt; IO Bool
</span><a href="GHC.IO.Device.html#isSeekable"><span class="hs-identifier hs-var">IODevice.isSeekable</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548274"><span class="hs-identifier hs-var">dev</span></a></span><span>
</span><span id="line-325"></span><span>              </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679548272"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO a
</span><a href="#local-6989586621679548282"><span class="hs-identifier hs-var">act</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548281"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-326"></span><span>                   </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IO a
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notSeekable"><span class="hs-identifier hs-var">ioe_notSeekable</span></a></span><span>
</span><span id="line-327"></span><span>
</span><span id="line-328"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-329"></span><span class="hs-comment">-- Handy IOErrors</span><span>
</span><span id="line-330"></span><span>
</span><span id="line-331"></span><span id="local-6989586621679548772"><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_closedHandle"><span class="hs-identifier hs-type">ioe_closedHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_semiclosedHandle"><span class="hs-identifier hs-type">ioe_semiclosedHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier hs-type">ioe_EOF</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-332"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_notReadable"><span class="hs-identifier hs-type">ioe_notReadable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_notWritable"><span class="hs-identifier hs-type">ioe_notWritable</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_cannotFlushNotSeekable"><span class="hs-identifier hs-type">ioe_cannotFlushNotSeekable</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-333"></span><span>  </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_notSeekable"><span class="hs-identifier hs-type">ioe_notSeekable</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548772"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-334"></span><span>
</span><span id="line-335"></span><span id="ioe_closedHandle"><span class="annot"><span class="annottext">ioe_closedHandle :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_closedHandle"><span class="hs-identifier hs-var hs-var">ioe_closedHandle</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-336"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-337"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is closed&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-338"></span><span id="ioe_semiclosedHandle"><span class="annot"><span class="annottext">ioe_semiclosedHandle :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_semiclosedHandle"><span class="hs-identifier hs-var hs-var">ioe_semiclosedHandle</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-339"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-340"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is semi-closed&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-341"></span><span id="ioe_EOF"><span class="annot"><span class="annottext">ioe_EOF :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier hs-var hs-var">ioe_EOF</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-342"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#EOF"><span class="hs-identifier hs-var">EOF</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-343"></span><span id="ioe_notReadable"><span class="annot"><span class="annottext">ioe_notReadable :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notReadable"><span class="hs-identifier hs-var hs-var">ioe_notReadable</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-344"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-345"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is not open for reading&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-346"></span><span id="ioe_notWritable"><span class="annot"><span class="annottext">ioe_notWritable :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notWritable"><span class="hs-identifier hs-var hs-var">ioe_notWritable</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-347"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-348"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is not open for writing&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-349"></span><span id="ioe_notSeekable"><span class="annot"><span class="annottext">ioe_notSeekable :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_notSeekable"><span class="hs-identifier hs-var hs-var">ioe_notSeekable</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-350"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-351"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is not seekable&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-352"></span><span id="ioe_cannotFlushNotSeekable"><span class="annot"><span class="annottext">ioe_cannotFlushNotSeekable :: forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_cannotFlushNotSeekable"><span class="hs-identifier hs-var hs-var">ioe_cannotFlushNotSeekable</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-353"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-354"></span><span>      </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;cannot flush the read buffer: underlying device is not seekable&quot;</span></span><span>
</span><span id="line-355"></span><span>        </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-356"></span><span>
</span><span id="line-357"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_finalizedHandle"><span class="hs-identifier hs-type">ioe_finalizedHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span>
</span><span id="line-358"></span><span id="ioe_finalizedHandle"><span class="annot"><span class="annottext">ioe_finalizedHandle :: FilePath -&gt; Handle__
</span><a href="GHC.IO.Handle.Internals.html#ioe_finalizedHandle"><span class="hs-identifier hs-var hs-var">ioe_finalizedHandle</span></a></span></span><span> </span><span id="local-6989586621679548268"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548268"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; Handle__
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span>
</span><span id="line-359"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-360"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;handle is finalized&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; Maybe FilePath
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548268"><span class="hs-identifier hs-var">fp</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-361"></span><span>
</span><span id="line-362"></span><span id="local-6989586621679548743"><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioe_bufsiz"><span class="hs-identifier hs-type">ioe_bufsiz</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548743"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-363"></span><span id="ioe_bufsiz"><span class="annot"><span class="annottext">ioe_bufsiz :: forall a. Int -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_bufsiz"><span class="hs-identifier hs-var hs-var">ioe_bufsiz</span></a></span></span><span> </span><span id="local-6989586621679548264"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679548264"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IOException -&gt; IO a
forall a. IOException -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-364"></span><span>   </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; FilePath
-&gt; FilePath
-&gt; Maybe CInt
-&gt; Maybe FilePath
-&gt; IOException
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Handle
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InvalidArgument"><span class="hs-identifier hs-var">InvalidArgument</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;hSetBuffering&quot;</span></span><span>
</span><span id="line-365"></span><span>        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;illegal buffer size &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; FilePath -&gt; FilePath
forall a. Show a =&gt; Int -&gt; a -&gt; FilePath -&gt; FilePath
</span><a href="GHC.Show.html#showsPrec"><span class="hs-identifier hs-var">showsPrec</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">9</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679548264"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe FilePath
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-366"></span><span>                                </span><span class="hs-comment">-- 9 =&gt; should be parens'ified.</span><span>
</span><span id="line-367"></span><span>
</span><span id="line-368"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-369"></span><span class="hs-comment">-- Wrapper for Handle encoding/decoding.</span><span>
</span><span id="line-370"></span><span>
</span><span id="line-371"></span><span class="hs-comment">-- The interface for TextEncoding changed so that a TextEncoding doesn't raise</span><span>
</span><span id="line-372"></span><span class="hs-comment">-- an exception if it encounters an invalid sequence. Furthermore, encoding</span><span>
</span><span id="line-373"></span><span class="hs-comment">-- returns a reason as to why encoding stopped, letting us know if it was due</span><span>
</span><span id="line-374"></span><span class="hs-comment">-- to input/output underflow or an invalid sequence.</span><span>
</span><span id="line-375"></span><span class="hs-comment">--</span><span>
</span><span id="line-376"></span><span class="hs-comment">-- This code adapts this elaborated interface back to the original TextEncoding</span><span>
</span><span id="line-377"></span><span class="hs-comment">-- interface.</span><span>
</span><span id="line-378"></span><span class="hs-comment">--</span><span>
</span><span id="line-379"></span><span class="hs-comment">-- FIXME: it is possible that Handle code using the haDecoder/haEncoder fields</span><span>
</span><span id="line-380"></span><span class="hs-comment">-- could be made clearer by using the 'encode' interface directly. I have not</span><span>
</span><span id="line-381"></span><span class="hs-comment">-- looked into this.</span><span>
</span><span id="line-382"></span><span>
</span><span id="line-383"></span><span id="local-6989586621679548739"><span id="local-6989586621679548740"><span id="local-6989586621679548741"><span class="annot"><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-type">streamEncode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#BufferCodec"><span class="hs-identifier hs-type">BufferCodec</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548741"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548740"><span class="hs-identifier hs-type">to</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548739"><span class="hs-identifier hs-type">state</span></a></span><span>
</span><span id="line-384"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548741"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548740"><span class="hs-identifier hs-type">to</span></a></span><span>
</span><span id="line-385"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548741"><span class="hs-identifier hs-type">from</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548740"><span class="hs-identifier hs-type">to</span></a></span><span class="hs-special">)</span></span></span></span><span>
</span><span id="line-386"></span><span id="streamEncode"><span class="annot"><span class="annottext">streamEncode :: forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-var hs-var">streamEncode</span></a></span></span><span> </span><span id="local-6989586621679548258"><span class="annot"><span class="annottext">BufferCodec from to state
</span><a href="#local-6989586621679548258"><span class="hs-identifier hs-var">codec</span></a></span></span><span> </span><span id="local-6989586621679548257"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548257"><span class="hs-identifier hs-var">from</span></a></span></span><span> </span><span id="local-6989586621679548256"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548256"><span class="hs-identifier hs-var">to</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">((CodingProgress, Buffer from, Buffer to)
 -&gt; (Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
-&gt; IO (Buffer from, Buffer to)
forall (f :: * -&gt; *) a b. Functor f =&gt; (a -&gt; b) -&gt; f a -&gt; f b
</span><a href="GHC.Base.html#fmap"><span class="hs-identifier hs-var">fmap</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679548255"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548255"><span class="hs-identifier hs-var">from'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679548254"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548254"><span class="hs-identifier hs-var">to'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548255"><span class="hs-identifier hs-var">from'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548254"><span class="hs-identifier hs-var">to'</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO (CodingProgress, Buffer from, Buffer to)
 -&gt; IO (Buffer from, Buffer to))
-&gt; IO (CodingProgress, Buffer from, Buffer to)
-&gt; IO (Buffer from, Buffer to)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">BufferCodec from to state -&gt; CodeBuffer from to
forall from to state.
BufferCodec from to state -&gt; CodeBuffer from to
</span><a href="GHC.IO.Handle.Internals.html#recoveringEncode"><span class="hs-identifier hs-var">recoveringEncode</span></a></span><span> </span><span class="annot"><span class="annottext">BufferCodec from to state
</span><a href="#local-6989586621679548258"><span class="hs-identifier hs-var">codec</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548257"><span class="hs-identifier hs-var">from</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548256"><span class="hs-identifier hs-var">to</span></a></span><span>
</span><span id="line-387"></span><span>
</span><span id="line-388"></span><span class="hs-comment">-- | Just like 'encode', but interleaves calls to 'encode' with calls to 'recover' in order to make as much progress as possible</span><span>
</span><span id="line-389"></span><span id="local-6989586621679548727"><span id="local-6989586621679548728"><span id="local-6989586621679548729"><span class="annot"><a href="GHC.IO.Handle.Internals.html#recoveringEncode"><span class="hs-identifier hs-type">recoveringEncode</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#BufferCodec"><span class="hs-identifier hs-type">BufferCodec</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548729"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548728"><span class="hs-identifier hs-type">to</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548727"><span class="hs-identifier hs-type">state</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#CodeBuffer"><span class="hs-identifier hs-type">CodeBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548729"><span class="hs-identifier hs-type">from</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548728"><span class="hs-identifier hs-type">to</span></a></span></span></span></span><span>
</span><span id="line-390"></span><span id="recoveringEncode"><span class="annot"><span class="annottext">recoveringEncode :: forall from to state.
BufferCodec from to state -&gt; CodeBuffer from to
</span><a href="GHC.IO.Handle.Internals.html#recoveringEncode"><span class="hs-identifier hs-var hs-var">recoveringEncode</span></a></span></span><span> </span><span id="local-6989586621679548252"><span class="annot"><span class="annottext">BufferCodec from to state
</span><a href="#local-6989586621679548252"><span class="hs-identifier hs-var">codec</span></a></span></span><span> </span><span id="local-6989586621679548251"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548251"><span class="hs-identifier hs-var">from</span></a></span></span><span> </span><span id="local-6989586621679548250"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548250"><span class="hs-identifier hs-var">to</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer from
-&gt; Buffer to -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679548249"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548251"><span class="hs-identifier hs-var">from</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548250"><span class="hs-identifier hs-var">to</span></a></span><span>
</span><span id="line-391"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-392"></span><span>    </span><span id="local-6989586621679548249"><span class="annot"><span class="annottext">go :: Buffer from
-&gt; Buffer to -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679548249"><span class="hs-identifier hs-var hs-var">go</span></a></span></span><span> </span><span id="local-6989586621679548243"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548243"><span class="hs-identifier hs-var">from</span></a></span></span><span> </span><span id="local-6989586621679548242"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548242"><span class="hs-identifier hs-var">to</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-393"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621679548241"><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679548241"><span class="hs-identifier hs-var">why</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679548240"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548240"><span class="hs-identifier hs-var">from'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679548239"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548239"><span class="hs-identifier hs-var">to'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">BufferCodec from to state
-&gt; Buffer from
-&gt; Buffer to
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall from to state.
BufferCodec from to state -&gt; CodeBuffer from to
</span><a href="GHC.IO.Encoding.Types.html#encode"><span class="hs-identifier hs-var hs-var">encode</span></a></span><span> </span><span class="annot"><span class="annottext">BufferCodec from to state
</span><a href="#local-6989586621679548252"><span class="hs-identifier hs-var">codec</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548243"><span class="hs-identifier hs-var">from</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548242"><span class="hs-identifier hs-var">to</span></a></span><span>
</span><span id="line-394"></span><span>      </span><span class="hs-comment">-- When we are dealing with Handles, we don't care about input/output</span><span>
</span><span id="line-395"></span><span>      </span><span class="hs-comment">-- underflow particularly, and we want to delay errors about invalid</span><span>
</span><span id="line-396"></span><span>      </span><span class="hs-comment">-- sequences as far as possible.</span><span>
</span><span id="line-397"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679548241"><span class="hs-identifier hs-var">why</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-398"></span><span>        </span><span class="annot"><span class="annottext">CodingProgress
</span><a href="GHC.IO.Encoding.Types.html#InvalidSequence"><span class="hs-identifier hs-var">InvalidSequence</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548243"><span class="hs-identifier hs-var">from</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548240"><span class="hs-identifier hs-var">from'</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-399"></span><span>          </span><span class="hs-comment">-- NB: it is OK to call recover here. Because we saw InvalidSequence, by the invariants</span><span>
</span><span id="line-400"></span><span>          </span><span class="hs-comment">-- on &quot;encode&quot; it must be the case that there is at least one elements available in the output</span><span>
</span><span id="line-401"></span><span>          </span><span class="hs-comment">-- buffer. Furthermore, clearly there is at least one element in the input buffer since we found</span><span>
</span><span id="line-402"></span><span>          </span><span class="hs-comment">-- something invalid there!</span><span>
</span><span id="line-403"></span><span>          </span><span class="hs-special">(</span><span id="local-6989586621679548235"><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548235"><span class="hs-identifier hs-var">from'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679548234"><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548234"><span class="hs-identifier hs-var">to'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Encoding.Types.html#recover"><span class="hs-identifier hs-var hs-var">recover</span></a></span><span> </span><span class="annot"><span class="annottext">BufferCodec from to state
</span><a href="#local-6989586621679548252"><span class="hs-identifier hs-var">codec</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548240"><span class="hs-identifier hs-var">from'</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548239"><span class="hs-identifier hs-var">to'</span></a></span><span>
</span><span id="line-404"></span><span>          </span><span class="annot"><span class="annottext">Buffer from
-&gt; Buffer to -&gt; IO (CodingProgress, Buffer from, Buffer to)
</span><a href="#local-6989586621679548249"><span class="hs-identifier hs-var">go</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548235"><span class="hs-identifier hs-var">from'</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548234"><span class="hs-identifier hs-var">to'</span></a></span><span>
</span><span id="line-405"></span><span>        </span><span class="annot"><span class="annottext">CodingProgress
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(CodingProgress, Buffer from, Buffer to)
-&gt; IO (CodingProgress, Buffer from, Buffer to)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">CodingProgress
</span><a href="#local-6989586621679548241"><span class="hs-identifier hs-var">why</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer from
</span><a href="#local-6989586621679548240"><span class="hs-identifier hs-var">from'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer to
</span><a href="#local-6989586621679548239"><span class="hs-identifier hs-var">to'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-406"></span><span>
</span><span id="line-407"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-408"></span><span class="hs-comment">-- Handle Finalizers</span><span>
</span><span id="line-409"></span><span>
</span><span id="line-410"></span><span class="hs-comment">-- For a duplex handle, we arrange that the read side points to the write side</span><span>
</span><span id="line-411"></span><span class="hs-comment">-- (and hence keeps it alive if the read side is alive).  This is done by</span><span>
</span><span id="line-412"></span><span class="hs-comment">-- having the haOtherSide field of the read side point to the read side.</span><span>
</span><span id="line-413"></span><span class="hs-comment">-- The finalizer is then placed on the write side, and the handle only gets</span><span>
</span><span id="line-414"></span><span class="hs-comment">-- finalized once, when both sides are no longer required.</span><span>
</span><span id="line-415"></span><span>
</span><span id="line-416"></span><span class="hs-comment">-- NOTE about finalized handles: It's possible that a handle can be</span><span>
</span><span id="line-417"></span><span class="hs-comment">-- finalized and then we try to use it later, for example if the</span><span>
</span><span id="line-418"></span><span class="hs-comment">-- handle is referenced from another finalizer, or from a thread that</span><span>
</span><span id="line-419"></span><span class="hs-comment">-- has become unreferenced and then resurrected (arguably in the</span><span>
</span><span id="line-420"></span><span class="hs-comment">-- latter case we shouldn't finalize the Handle...).  Anyway,</span><span>
</span><span id="line-421"></span><span class="hs-comment">-- we try to emit a helpful message which is better than nothing.</span><span>
</span><span id="line-422"></span><span class="hs-comment">--</span><span>
</span><span id="line-423"></span><span class="hs-comment">-- [later; 8/2010] However, a program like this can yield a strange</span><span>
</span><span id="line-424"></span><span class="hs-comment">-- error message:</span><span>
</span><span id="line-425"></span><span class="hs-comment">--</span><span>
</span><span id="line-426"></span><span class="hs-comment">--   main = writeFile &quot;out&quot; loop</span><span>
</span><span id="line-427"></span><span class="hs-comment">--   loop = let x = x in x</span><span>
</span><span id="line-428"></span><span class="hs-comment">--</span><span>
</span><span id="line-429"></span><span class="hs-comment">-- because the main thread and the Handle are both unreachable at the</span><span>
</span><span id="line-430"></span><span class="hs-comment">-- same time, the Handle may get finalized before the main thread</span><span>
</span><span id="line-431"></span><span class="hs-comment">-- receives the NonTermination exception, and the exception handler</span><span>
</span><span id="line-432"></span><span class="hs-comment">-- will then report an error.  We'd rather this was not an error and</span><span>
</span><span id="line-433"></span><span class="hs-comment">-- the program just prints &quot;&lt;&lt;loop&gt;&gt;&quot;.</span><span>
</span><span id="line-434"></span><span>
</span><span id="line-435"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#handleFinalizer"><span class="hs-identifier hs-type">handleFinalizer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-436"></span><span id="handleFinalizer"><span class="annot"><span class="annottext">handleFinalizer :: HandleFinalizer
</span><a href="GHC.IO.Handle.Internals.html#handleFinalizer"><span class="hs-identifier hs-var hs-var">handleFinalizer</span></a></span></span><span> </span><span id="local-6989586621679548232"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679548232"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span id="local-6989586621679548231"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548231"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-437"></span><span>  </span><span id="local-6989586621679548230"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548230"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; IO Handle__
forall a. MVar a -&gt; IO a
</span><a href="GHC.MVar.html#takeMVar"><span class="hs-identifier hs-var">takeMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548231"><span class="hs-identifier hs-var">m</span></a></span><span>
</span><span id="line-438"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679548229"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548229"><span class="hs-identifier hs-var">handle_'</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#hClose_help"><span class="hs-identifier hs-var">hClose_help</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548230"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-439"></span><span>  </span><span class="annot"><span class="annottext">MVar Handle__ -&gt; Handle__ -&gt; IO ()
forall a. MVar a -&gt; a -&gt; IO ()
</span><a href="GHC.MVar.html#putMVar"><span class="hs-identifier hs-var">putMVar</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679548231"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548229"><span class="hs-identifier hs-var">handle_'</span></a></span><span>
</span><span id="line-440"></span><span>  </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-441"></span><span>
</span><span id="line-442"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-443"></span><span class="hs-comment">-- Allocating buffers</span><span>
</span><span id="line-444"></span><span>
</span><span id="line-445"></span><span class="hs-comment">-- using an 8k char buffer instead of 32k improved performance for a</span><span>
</span><span id="line-446"></span><span class="hs-comment">-- basic &quot;cat&quot; program by ~30% for me.  --SDM</span><span>
</span><span id="line-447"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#dEFAULT_CHAR_BUFFER_SIZE"><span class="hs-identifier hs-type">dEFAULT_CHAR_BUFFER_SIZE</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-448"></span><span id="dEFAULT_CHAR_BUFFER_SIZE"><span class="annot"><span class="annottext">dEFAULT_CHAR_BUFFER_SIZE :: Int
</span><a href="GHC.IO.Handle.Internals.html#dEFAULT_CHAR_BUFFER_SIZE"><span class="hs-identifier hs-var hs-var">dEFAULT_CHAR_BUFFER_SIZE</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2048</span></span><span> </span><span class="hs-comment">-- 8k/sizeof(HsChar)</span><span>
</span><span id="line-449"></span><span>
</span><span id="line-450"></span><span id="local-6989586621679548721"><span class="annot"><a href="GHC.IO.Handle.Internals.html#getCharBuffer"><span class="hs-identifier hs-type">getCharBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#IODevice"><span class="hs-identifier hs-type">IODevice</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548721"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679548721"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span>
</span><span id="line-451"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier hs-type">IORef</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#BufferMode"><span class="hs-identifier hs-type">BufferMode</span></a></span><span class="hs-special">)</span></span><span>
</span><span id="line-452"></span><span id="getCharBuffer"><span class="annot"><span class="annottext">getCharBuffer :: forall dev.
IODevice dev =&gt;
dev -&gt; BufferState -&gt; IO (IORef (Buffer Char), BufferMode)
</span><a href="GHC.IO.Handle.Internals.html#getCharBuffer"><span class="hs-identifier hs-var hs-var">getCharBuffer</span></a></span></span><span> </span><span id="local-6989586621679548220"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548220"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679548219"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679548219"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-453"></span><span>  </span><span id="local-6989586621679548218"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548218"><span class="hs-identifier hs-var">buffer</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-var">newCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Handle.Internals.html#dEFAULT_CHAR_BUFFER_SIZE"><span class="hs-identifier hs-var">dEFAULT_CHAR_BUFFER_SIZE</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679548219"><span class="hs-identifier hs-var">state</span></a></span><span>
</span><span id="line-454"></span><span>  </span><span id="local-6989586621679548216"><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548216"><span class="hs-identifier hs-var">ioref</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (IORef (Buffer Char))
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548218"><span class="hs-identifier hs-var">buffer</span></a></span><span>
</span><span id="line-455"></span><span>  </span><span id="local-6989586621679548214"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679548214"><span class="hs-identifier hs-var">is_tty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; IO Bool
forall a. IODevice a =&gt; a -&gt; IO Bool
</span><a href="GHC.IO.Device.html#isTerminal"><span class="hs-identifier hs-var">IODevice.isTerminal</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548220"><span class="hs-identifier hs-var">dev</span></a></span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679548212"><span class="annot"><span class="annottext">buffer_mode :: BufferMode
</span><a href="#local-6989586621679548212"><span class="hs-identifier hs-var hs-var">buffer_mode</span></a></span></span><span>
</span><span id="line-458"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679548214"><span class="hs-identifier hs-var">is_tty</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#LineBuffering"><span class="hs-identifier hs-var">LineBuffering</span></a></span><span>
</span><span id="line-459"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe Int -&gt; BufferMode
</span><a href="GHC.IO.Handle.Types.html#BlockBuffering"><span class="hs-identifier hs-var">BlockBuffering</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Int
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-460"></span><span>
</span><span id="line-461"></span><span>  </span><span class="annot"><span class="annottext">(IORef (Buffer Char), BufferMode)
-&gt; IO (IORef (Buffer Char), BufferMode)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548216"><span class="hs-identifier hs-var">ioref</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679548212"><span class="hs-identifier hs-var">buffer_mode</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-462"></span><span>
</span><span id="line-463"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkUnBuffer"><span class="hs-identifier hs-type">mkUnBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IORef.html#IORef"><span class="hs-identifier hs-type">IORef</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#BufferMode"><span class="hs-identifier hs-type">BufferMode</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-464"></span><span id="mkUnBuffer"><span class="annot"><span class="annottext">mkUnBuffer :: BufferState -&gt; IO (IORef (Buffer Char), BufferMode)
</span><a href="GHC.IO.Handle.Internals.html#mkUnBuffer"><span class="hs-identifier hs-var hs-var">mkUnBuffer</span></a></span></span><span> </span><span id="local-6989586621679548208"><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679548208"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-465"></span><span>  </span><span id="local-6989586621679548207"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548207"><span class="hs-identifier hs-var">buffer</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-var">newCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Handle.Internals.html#dEFAULT_CHAR_BUFFER_SIZE"><span class="hs-identifier hs-var">dEFAULT_CHAR_BUFFER_SIZE</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679548208"><span class="hs-identifier hs-var">state</span></a></span><span>
</span><span id="line-466"></span><span>              </span><span class="hs-comment">--  See [note Buffer Sizing], GHC.IO.Handle.Types</span><span>
</span><span id="line-467"></span><span>  </span><span id="local-6989586621679548206"><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548206"><span class="hs-identifier hs-var">ref</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (IORef (Buffer Char))
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548207"><span class="hs-identifier hs-var">buffer</span></a></span><span>
</span><span id="line-468"></span><span>  </span><span class="annot"><span class="annottext">(IORef (Buffer Char), BufferMode)
-&gt; IO (IORef (Buffer Char), BufferMode)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548206"><span class="hs-identifier hs-var">ref</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#NoBuffering"><span class="hs-identifier hs-var">NoBuffering</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-469"></span><span>
</span><span id="line-470"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-471"></span><span class="hs-comment">-- Flushing buffers</span><span>
</span><span id="line-472"></span><span>
</span><span id="line-473"></span><span class="hs-comment">-- | syncs the file with the buffer, including moving the</span><span>
</span><span id="line-474"></span><span class="hs-comment">-- file pointer backwards in the case of a read buffer.  This can fail</span><span>
</span><span id="line-475"></span><span class="hs-comment">-- on a non-seekable read Handle.</span><span>
</span><span id="line-476"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushBuffer"><span class="hs-identifier hs-type">flushBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-477"></span><span id="flushBuffer"><span class="annot"><span class="annottext">flushBuffer :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushBuffer"><span class="hs-identifier hs-var hs-var">flushBuffer</span></a></span></span><span> </span><span id="local-6989586621679548204"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548204"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548185"><span id="local-6989586621679548186"><span id="local-6989586621679548187"><span id="local-6989586621679548188"><span id="local-6989586621679548189"><span id="local-6989586621679548190"><span id="local-6989586621679548191"><span id="local-6989586621679548192"><span id="local-6989586621679548193"><span id="local-6989586621679548194"><span id="local-6989586621679548195"><span id="local-6989586621679548196"><span id="local-6989586621679548197"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548185"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-478"></span><span>  </span><span id="local-6989586621679548184"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548184"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548192"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-479"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; BufferState
forall e. Buffer e -&gt; BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var hs-var">bufState</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548184"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-480"></span><span>    </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-481"></span><span>        </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var">flushCharReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548204"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-482"></span><span>        </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteReadBuffer"><span class="hs-identifier hs-var">flushByteReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548204"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-483"></span><span>    </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-484"></span><span>        </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var">flushByteWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548204"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-485"></span><span>
</span><span id="line-486"></span><span class="hs-comment">-- | flushes the Char buffer only.  Works on all Handles.</span><span>
</span><span id="line-487"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushCharBuffer"><span class="hs-identifier hs-type">flushCharBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-488"></span><span id="flushCharBuffer"><span class="annot"><span class="annottext">flushCharBuffer :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharBuffer"><span class="hs-identifier hs-var hs-var">flushCharBuffer</span></a></span></span><span> </span><span id="local-6989586621679548183"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548183"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548162"><span id="local-6989586621679548163"><span id="local-6989586621679548164"><span id="local-6989586621679548165"><span id="local-6989586621679548166"><span id="local-6989586621679548167"><span id="local-6989586621679548168"><span id="local-6989586621679548169"><span id="local-6989586621679548170"><span id="local-6989586621679548171"><span id="local-6989586621679548172"><span id="local-6989586621679548173"><span id="local-6989586621679548174"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548162"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-489"></span><span>  </span><span id="local-6989586621679548161"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548161"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548169"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-490"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; BufferState
forall e. Buffer e -&gt; BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var hs-var">bufState</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548161"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-491"></span><span>    </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-492"></span><span>        </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var">flushCharReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548183"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-493"></span><span>    </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-494"></span><span>        </span><span class="hs-comment">-- Nothing to do here. Char buffer on a write Handle is always empty</span><span>
</span><span id="line-495"></span><span>        </span><span class="hs-comment">-- between Handle operations.</span><span>
</span><span id="line-496"></span><span>        </span><span class="hs-comment">-- See [note Buffer Flushing], GHC.IO.Handle.Types.</span><span>
</span><span id="line-497"></span><span>        </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548161"><span class="hs-identifier hs-var">cbuf</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-498"></span><span>           </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
forall a. HasCallStack =&gt; FilePath -&gt; a
</span><a href="GHC.Err.html#error"><span class="hs-identifier hs-var">error</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;internal IO library error: Char buffer non-empty&quot;</span></span><span>
</span><span id="line-499"></span><span>
</span><span id="line-500"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-501"></span><span class="hs-comment">-- Writing data (flushing write buffers)</span><span>
</span><span id="line-502"></span><span>
</span><span id="line-503"></span><span class="hs-comment">-- flushWriteBuffer flushes the byte buffer iff it contains pending write</span><span>
</span><span id="line-504"></span><span class="hs-comment">-- data. Because the Char buffer on a write Handle is always empty between</span><span>
</span><span id="line-505"></span><span class="hs-comment">-- Handle operations (see [note Buffer Flushing], GHC.IO.Handle.Types),</span><span>
</span><span id="line-506"></span><span class="hs-comment">-- both buffers are empty after this.</span><span>
</span><span id="line-507"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-type">flushWriteBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-508"></span><span id="flushWriteBuffer"><span class="annot"><span class="annottext">flushWriteBuffer :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-var hs-var">flushWriteBuffer</span></a></span></span><span> </span><span id="local-6989586621679548159"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548159"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548140"><span id="local-6989586621679548141"><span id="local-6989586621679548142"><span id="local-6989586621679548143"><span id="local-6989586621679548144"><span id="local-6989586621679548145"><span id="local-6989586621679548146"><span id="local-6989586621679548147"><span id="local-6989586621679548148"><span id="local-6989586621679548149"><span id="local-6989586621679548150"><span id="local-6989586621679548151"><span id="local-6989586621679548152"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548140"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-509"></span><span>  </span><span id="local-6989586621679548139"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548139"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548150"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-510"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier hs-var">isWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548139"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var">flushByteWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548159"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-511"></span><span>
</span><span id="line-512"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-type">flushByteWriteBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-513"></span><span id="flushByteWriteBuffer"><span class="annot"><span class="annottext">flushByteWriteBuffer :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var hs-var">flushByteWriteBuffer</span></a></span></span><span> </span><span id="local-6989586621679548138"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548138"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548116"><span id="local-6989586621679548117"><span id="local-6989586621679548118"><span id="local-6989586621679548119"><span id="local-6989586621679548120"><span id="local-6989586621679548121"><span id="local-6989586621679548122"><span id="local-6989586621679548123"><span id="local-6989586621679548124"><span id="local-6989586621679548125"><span id="local-6989586621679548126"><span id="local-6989586621679548127"><span id="local-6989586621679548128"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548116"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-514"></span><span>  </span><span id="local-6989586621679548115"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548115"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548126"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-515"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548115"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-516"></span><span>    </span><span id="local-6989586621679548114"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548114"><span class="hs-identifier hs-var">bbuf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#flushWriteBuffer"><span class="hs-identifier hs-var">Buffered.flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548128"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548115"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-517"></span><span>    </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;flushByteWriteBuffer: bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548114"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-518"></span><span>    </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548126"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548114"><span class="hs-identifier hs-var">bbuf'</span></a></span><span>
</span><span id="line-519"></span><span>
</span><span id="line-520"></span><span class="hs-comment">-- write the contents of the CharBuffer to the Handle__.</span><span>
</span><span id="line-521"></span><span class="hs-comment">-- The data will be encoded and pushed to the byte buffer,</span><span>
</span><span id="line-522"></span><span class="hs-comment">-- flushing if the buffer becomes full.</span><span>
</span><span id="line-523"></span><span class="hs-comment">-- Data is written to the handles current buffer offset.</span><span>
</span><span id="line-524"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-type">writeCharBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-525"></span><span id="writeCharBuffer"><span class="annot"><span class="annottext">writeCharBuffer :: Handle__ -&gt; Buffer Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-var hs-var">writeCharBuffer</span></a></span></span><span> </span><span id="local-6989586621679548111"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548111"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548082"><span id="local-6989586621679548083"><span id="local-6989586621679548084"><span id="local-6989586621679548085"><span id="local-6989586621679548086"><span id="local-6989586621679548087"><span id="local-6989586621679548088"><span id="local-6989586621679548089"><span id="local-6989586621679548090"><span id="local-6989586621679548091"><span id="local-6989586621679548092"><span id="local-6989586621679548093"><span id="local-6989586621679548094"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548082"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679548081"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548081"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-526"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-527"></span><span>  </span><span id="local-6989586621679548080"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548080"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548092"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-528"></span><span>
</span><span id="line-529"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;writeCharBuffer: cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548081"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span>
</span><span id="line-530"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot; bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548080"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-531"></span><span>
</span><span id="line-532"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679548079"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548079"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679548078"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548078"><span class="hs-identifier hs-var">bbuf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder enc_state)
</span><a href="#local-6989586621679548087"><span class="hs-identifier hs-var">haEncoder</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-533"></span><span>    </span><span class="annot"><span class="annottext">Maybe (TextEncoder enc_state)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Buffer Word8 -&gt; IO (Buffer Char, Buffer Word8)
</span><a href="GHC.IO.Encoding.html#latin1_encode"><span class="hs-identifier hs-var">latin1_encode</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548081"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548080"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-534"></span><span>    </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679548076"><span class="annot"><span class="annottext">TextEncoder enc_state
</span><a href="#local-6989586621679548076"><span class="hs-identifier hs-var">encoder</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoder enc_state
-&gt; Buffer Char -&gt; Buffer Word8 -&gt; IO (Buffer Char, Buffer Word8)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-var">streamEncode</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoder enc_state
</span><a href="#local-6989586621679548076"><span class="hs-identifier hs-var">encoder</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548081"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548080"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-535"></span><span>
</span><span id="line-536"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;writeCharBuffer after encoding: cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548079"><span class="hs-identifier hs-var">cbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span>
</span><span id="line-537"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot; bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548078"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-538"></span><span>
</span><span id="line-539"></span><span>          </span><span class="hs-comment">-- flush the byte buffer if it is full</span><span>
</span><span id="line-540"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isFullBuffer"><span class="hs-identifier hs-var">isFullBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548078"><span class="hs-identifier hs-var">bbuf'</span></a></span><span>
</span><span id="line-541"></span><span>          </span><span class="hs-comment">--  or we made no progress</span><span>
</span><span id="line-542"></span><span>     </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548079"><span class="hs-identifier hs-var">cbuf'</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548079"><span class="hs-identifier hs-var">cbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548081"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-543"></span><span>          </span><span class="hs-comment">-- or the byte buffer has more elements than the user wanted buffered</span><span>
</span><span id="line-544"></span><span>     </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679548091"><span class="hs-identifier hs-var">haBufferMode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-545"></span><span>          </span><span class="annot"><a href="GHC.IO.Handle.Types.html#BlockBuffering"><span class="hs-identifier hs-type">BlockBuffering</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679548072"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679548072"><span class="hs-identifier hs-var">s</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548078"><span class="hs-identifier hs-var">bbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679548072"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-546"></span><span>          </span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#NoBuffering"><span class="hs-identifier hs-var">NoBuffering</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-547"></span><span>          </span><span id="local-6989586621679548070"><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679548070"><span class="hs-identifier hs-var">_other</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-548"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-549"></span><span>      </span><span id="local-6989586621679548069"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548069"><span class="hs-identifier hs-var">bbuf''</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#flushWriteBuffer"><span class="hs-identifier hs-var">Buffered.flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548094"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548078"><span class="hs-identifier hs-var">bbuf'</span></a></span><span>
</span><span id="line-550"></span><span>      </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548092"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548069"><span class="hs-identifier hs-var">bbuf''</span></a></span><span>
</span><span id="line-551"></span><span>      </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;writeCharBuffer after flushing: cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548069"><span class="hs-identifier hs-var">bbuf''</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-552"></span><span>    </span><span class="hs-keyword">else</span><span>
</span><span id="line-553"></span><span>      </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548092"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548078"><span class="hs-identifier hs-var">bbuf'</span></a></span><span>
</span><span id="line-554"></span><span>
</span><span id="line-555"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548079"><span class="hs-identifier hs-var">cbuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-556"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-var">writeCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679548111"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548079"><span class="hs-identifier hs-var">cbuf'</span></a></span><span>
</span><span id="line-557"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-558"></span><span>
</span><span id="line-559"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-560"></span><span class="hs-comment">-- Flushing read buffers</span><span>
</span><span id="line-561"></span><span>
</span><span id="line-562"></span><span class="hs-comment">-- It is always possible to flush the Char buffer back to the byte buffer.</span><span>
</span><span id="line-563"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-type">flushCharReadBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-564"></span><span id="flushCharReadBuffer"><span class="annot"><span class="annottext">flushCharReadBuffer :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var hs-var">flushCharReadBuffer</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679548038"><span id="local-6989586621679548039"><span id="local-6989586621679548040"><span id="local-6989586621679548041"><span id="local-6989586621679548042"><span id="local-6989586621679548043"><span id="local-6989586621679548044"><span id="local-6989586621679548045"><span id="local-6989586621679548046"><span id="local-6989586621679548047"><span id="local-6989586621679548048"><span id="local-6989586621679548049"><span id="local-6989586621679548050"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679548038"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-565"></span><span>  </span><span id="local-6989586621679548037"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548037"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548045"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-566"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isWriteBuffer"><span class="hs-identifier hs-var">isWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548037"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%7C%7C"><span class="hs-operator hs-var">||</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548037"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-567"></span><span>
</span><span id="line-568"></span><span>  </span><span class="hs-comment">-- haLastDecode is the byte buffer just before we did our last batch of</span><span>
</span><span id="line-569"></span><span>  </span><span class="hs-comment">-- decoding.  We're going to re-decode the bytes up to the current char,</span><span>
</span><span id="line-570"></span><span>  </span><span class="hs-comment">-- to find out where we should revert the byte buffer to.</span><span>
</span><span id="line-571"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679548036"><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679548036"><span class="hs-identifier hs-var">codec_state</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679548035"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548035"><span class="hs-identifier hs-var">bbuf0</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8) -&gt; IO (dec_state, Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
</span><a href="#local-6989586621679548046"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span>
</span><span id="line-572"></span><span>
</span><span id="line-573"></span><span>  </span><span id="local-6989586621679548034"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548045"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-574"></span><span>  </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679548045"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-575"></span><span>
</span><span id="line-576"></span><span>  </span><span class="hs-comment">-- if we haven't used any characters from the char buffer, then just</span><span>
</span><span id="line-577"></span><span>  </span><span class="hs-comment">-- re-install the old byte buffer.</span><span>
</span><span id="line-578"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-579"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548048"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548035"><span class="hs-identifier hs-var">bbuf0</span></a></span><span>
</span><span id="line-580"></span><span>             </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-581"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-582"></span><span>
</span><span id="line-583"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="#local-6989586621679548042"><span class="hs-identifier hs-var">haDecoder</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-584"></span><span>    </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-585"></span><span>      </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548048"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548035"><span class="hs-identifier hs-var">bbuf0</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548035"><span class="hs-identifier hs-var">bbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-586"></span><span>      </span><span class="hs-comment">-- no decoder: the number of bytes to decode is the same as the</span><span>
</span><span id="line-587"></span><span>      </span><span class="hs-comment">-- number of chars we have used up.</span><span>
</span><span id="line-588"></span><span>
</span><span id="line-589"></span><span>    </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679548031"><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679548031"><span class="hs-identifier hs-var">decoder</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-590"></span><span>      </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;flushCharReadBuffer re-decode, bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548035"><span class="hs-identifier hs-var">bbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span>
</span><span id="line-591"></span><span>               </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot; cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-592"></span><span>
</span><span id="line-593"></span><span>      </span><span class="hs-comment">-- restore the codec state</span><span>
</span><span id="line-594"></span><span>      </span><span class="annot"><span class="annottext">TextDecoder dec_state -&gt; dec_state -&gt; IO ()
forall from to state. BufferCodec from to state -&gt; state -&gt; IO ()
</span><a href="GHC.IO.Encoding.Types.html#setState"><span class="hs-identifier hs-var hs-var">setState</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679548031"><span class="hs-identifier hs-var">decoder</span></a></span><span> </span><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679548036"><span class="hs-identifier hs-var">codec_state</span></a></span><span>
</span><span id="line-595"></span><span>
</span><span id="line-596"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621679548029"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548029"><span class="hs-identifier hs-var">bbuf1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679548028"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548028"><span class="hs-identifier hs-var">cbuf1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextDecoder dec_state
-&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-var">streamEncode</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679548031"><span class="hs-identifier hs-var">decoder</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548035"><span class="hs-identifier hs-var">bbuf0</span></a></span><span>
</span><span id="line-597"></span><span>                               </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679548034"><span class="hs-identifier hs-var">cbuf0</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-598"></span><span>
</span><span id="line-599"></span><span>      </span><span class="hs-comment">-- We should not need to update the offset here. The bytebuffer contains the</span><span>
</span><span id="line-600"></span><span>      </span><span class="hs-comment">-- offset for the next read after it's used up. But this function only flushes</span><span>
</span><span id="line-601"></span><span>      </span><span class="hs-comment">-- the char buffer.</span><span>
</span><span id="line-602"></span><span>      </span><span class="hs-comment">-- let bbuf2 = bbuf1 -- {bufOffset = bufOffset bbuf1 - fromIntegral (bufL bbuf1)}</span><span>
</span><span id="line-603"></span><span>      </span><span class="hs-comment">-- debugIO (&quot;finished, bbuf=&quot; ++ summaryBuffer bbuf2 ++</span><span>
</span><span id="line-604"></span><span>      </span><span class="hs-comment">--          &quot; cbuf=&quot; ++ summaryBuffer cbuf1)</span><span>
</span><span id="line-605"></span><span>
</span><span id="line-606"></span><span>      </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548048"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679548029"><span class="hs-identifier hs-var">bbuf1</span></a></span><span>
</span><span id="line-607"></span><span>
</span><span id="line-608"></span><span>
</span><span id="line-609"></span><span class="hs-comment">-- When flushing the byte read buffer, we seek backwards by the number</span><span>
</span><span id="line-610"></span><span class="hs-comment">-- of characters in the buffer.  The file descriptor must therefore be</span><span>
</span><span id="line-611"></span><span class="hs-comment">-- seekable: attempting to flush the read buffer on an unseekable</span><span>
</span><span id="line-612"></span><span class="hs-comment">-- handle is not allowed.</span><span>
</span><span id="line-613"></span><span>
</span><span id="line-614"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#flushByteReadBuffer"><span class="hs-identifier hs-type">flushByteReadBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-615"></span><span id="flushByteReadBuffer"><span class="annot"><span class="annottext">flushByteReadBuffer :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteReadBuffer"><span class="hs-identifier hs-var hs-var">flushByteReadBuffer</span></a></span></span><span> </span><span id="local-6989586621679548026"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679548026"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547999"><span id="local-6989586621679548000"><span id="local-6989586621679548001"><span id="local-6989586621679548002"><span id="local-6989586621679548003"><span id="local-6989586621679548004"><span id="local-6989586621679548005"><span id="local-6989586621679548006"><span id="local-6989586621679548007"><span id="local-6989586621679548008"><span id="local-6989586621679548009"><span id="local-6989586621679548010"><span id="local-6989586621679548011"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547999"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-616"></span><span>  </span><span id="local-6989586621679547998"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548009"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-617"></span><span>
</span><span id="line-618"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-619"></span><span>
</span><span id="line-620"></span><span>  </span><span id="local-6989586621679547997"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679547997"><span class="hs-identifier hs-var">seekable</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; IO Bool
forall a. IODevice a =&gt; a -&gt; IO Bool
</span><a href="GHC.IO.Device.html#isSeekable"><span class="hs-identifier hs-var">IODevice.isSeekable</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548011"><span class="hs-identifier hs-var">haDevice</span></a></span><span>
</span><span id="line-621"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679547997"><span class="hs-identifier hs-var">seekable</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">IO ()
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_cannotFlushNotSeekable"><span class="hs-identifier hs-var">ioe_cannotFlushNotSeekable</span></a></span><span>
</span><span id="line-622"></span><span>
</span><span id="line-623"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679547994"><span class="annot"><span class="annottext">seek :: Int
</span><a href="#local-6989586621679547994"><span class="hs-identifier hs-var hs-var">seek</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int
forall a. Num a =&gt; a -&gt; a
</span><a href="GHC.Num.html#negate"><span class="hs-identifier hs-var">negate</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-624"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679547988"><span class="annot"><span class="annottext">offset :: Word64
</span><a href="#local-6989586621679547988"><span class="hs-identifier hs-var hs-var">offset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var hs-var">bufOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; Word64 -&gt; Word64
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Word64
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-625"></span><span>
</span><span id="line-626"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;flushByteReadBuffer: new file offset = &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; FilePath
forall a. Show a =&gt; a -&gt; FilePath
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547994"><span class="hs-identifier hs-var">seek</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-627"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;flushByteReadBuffer: &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-628"></span><span>
</span><span id="line-629"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679547982"><span class="annot"><span class="annottext">mIOSeek :: IO Integer
</span><a href="#local-6989586621679547982"><span class="hs-identifier hs-var hs-var">mIOSeek</span></a></span></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">dev -&gt; SeekMode -&gt; Integer -&gt; IO Integer
forall a. IODevice a =&gt; a -&gt; SeekMode -&gt; Integer -&gt; IO Integer
</span><a href="GHC.IO.Device.html#seek"><span class="hs-identifier hs-var">IODevice.seek</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548011"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">SeekMode
</span><a href="GHC.IO.Device.html#RelativeSeek"><span class="hs-identifier hs-var">RelativeSeek</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Integer
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547994"><span class="hs-identifier hs-var">seek</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-630"></span><span>  </span><span class="hs-comment">-- win-io doesn't need this, but it allows us to error out on invalid offsets</span><span>
</span><span id="line-631"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679547975"><span class="annot"><span class="annottext">winIOSeek :: IO Integer
</span><a href="#local-6989586621679547975"><span class="hs-identifier hs-var hs-var">winIOSeek</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">dev -&gt; SeekMode -&gt; Integer -&gt; IO Integer
forall a. IODevice a =&gt; a -&gt; SeekMode -&gt; Integer -&gt; IO Integer
</span><a href="GHC.IO.Device.html#seek"><span class="hs-identifier hs-var">IODevice.seek</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679548011"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">SeekMode
</span><a href="GHC.IO.Device.html#AbsoluteSeek"><span class="hs-identifier hs-var">AbsoluteSeek</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word64 -&gt; Integer
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679547988"><span class="hs-identifier hs-var">offset</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-632"></span><span>
</span><span id="line-633"></span><span>  </span><span class="annot"><span class="annottext">Integer
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Integer
</span><a href="#local-6989586621679547982"><span class="hs-identifier hs-var">mIOSeek</span></a></span><span> </span><span class="annot"><span class="annottext">IO Integer -&gt; IO Integer -&gt; IO Integer
forall a. a -&gt; a -&gt; a
</span><a href="GHC.IO.SubSystem.html#%3C%21%3E"><span class="hs-operator hs-var">&lt;!&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">IO Integer
</span><a href="#local-6989586621679547975"><span class="hs-identifier hs-var">winIOSeek</span></a></span><span>  </span><span class="hs-comment">-- execute one of these two seek functions</span><span>
</span><span id="line-634"></span><span>
</span><span id="line-635"></span><span>  </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679548009"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547998"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679547988"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-636"></span><span>
</span><span id="line-637"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-638"></span><span class="hs-comment">-- Making Handles</span><span>
</span><span id="line-639"></span><span>
</span><span id="line-640"></span><span class="hs-comment">{- Note [Making offsets for append]
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  The WINIO subysstem keeps track of offsets for handles
  on the Haskell side of things instead of letting the OS
  handle it. This requires us to establish the correct offset
  for a handle on creation. This is usually zero but slightly
  more tedious for append modes. There we fall back on IODevice
  functionality to establish the size of the file and then set
  the offset accordingly. This is only required for WINIO.
-}</span><span>
</span><span id="line-651"></span><span>
</span><span id="line-652"></span><span id="local-6989586621679548682"><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-type">mkHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548682"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#IODevice"><span class="hs-identifier hs-type">IODevice</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548682"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html#BufferedIO"><span class="hs-identifier hs-type">BufferedIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548682"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Typeable.Internal.html#Typeable"><span class="hs-identifier hs-type">Typeable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548682"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679548682"><span class="hs-identifier hs-type">dev</span></a></span><span>
</span><span id="line-653"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-654"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#HandleType"><span class="hs-identifier hs-type">HandleType</span></a></span><span>
</span><span id="line-655"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>                     </span><span class="hs-comment">-- buffered?</span><span>
</span><span id="line-656"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span>
</span><span id="line-657"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#NewlineMode"><span class="hs-identifier hs-type">NewlineMode</span></a></span><span>
</span><span id="line-658"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#HandleFinalizer"><span class="hs-identifier hs-type">HandleFinalizer</span></a></span><span>
</span><span id="line-659"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.MVar.html#MVar"><span class="hs-identifier hs-type">MVar</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-660"></span><span>         </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span></span><span>
</span><span id="line-661"></span><span id="mkHandle"><span class="annot"><span class="annottext">mkHandle :: forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var hs-var">mkHandle</span></a></span></span><span> </span><span id="local-6989586621679547969"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547969"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679547968"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547968"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679547967"><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547967"><span class="hs-identifier hs-var">ha_type</span></a></span></span><span> </span><span id="local-6989586621679547966"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679547966"><span class="hs-identifier hs-var">buffered</span></a></span></span><span> </span><span id="local-6989586621679547965"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547965"><span class="hs-identifier hs-var">mb_codec</span></a></span></span><span> </span><span id="local-6989586621679547964"><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547964"><span class="hs-identifier hs-var">nl</span></a></span></span><span> </span><span id="local-6989586621679547963"><span class="annot"><span class="annottext">Maybe HandleFinalizer
</span><a href="#local-6989586621679547963"><span class="hs-identifier hs-var">finalizer</span></a></span></span><span> </span><span id="local-6989586621679547962"><span class="annot"><span class="annottext">Maybe (MVar Handle__)
</span><a href="#local-6989586621679547962"><span class="hs-identifier hs-var">other_side</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-662"></span><span>   </span><span class="annot"><span class="annottext">Maybe TextEncoding
-&gt; HandleType
-&gt; (forall es ds.
    Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO Handle)
-&gt; IO Handle
forall a.
Maybe TextEncoding
-&gt; HandleType
-&gt; (forall es ds.
    Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO a)
-&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#openTextEncoding"><span class="hs-identifier hs-var">openTextEncoding</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547965"><span class="hs-identifier hs-var">mb_codec</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547967"><span class="hs-identifier hs-var">ha_type</span></a></span><span> </span><span class="annot"><span class="annottext">((forall es ds.
  Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO Handle)
 -&gt; IO Handle)
-&gt; (forall es ds.
    Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO Handle)
-&gt; IO Handle
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679547948"><span class="annot"><span class="annottext">Maybe (TextEncoder es)
</span><a href="#local-6989586621679547948"><span class="hs-identifier hs-var">mb_encoder</span></a></span></span><span> </span><span id="local-6989586621679547947"><span class="annot"><span class="annottext">Maybe (TextDecoder ds)
</span><a href="#local-6989586621679547947"><span class="hs-identifier hs-var">mb_decoder</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-663"></span><span>
</span><span id="line-664"></span><span>   </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679547946"><span class="annot"><span class="annottext">buf_state :: BufferState
</span><a href="#local-6989586621679547946"><span class="hs-identifier hs-var hs-var">buf_state</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType -&gt; BufferState
</span><a href="GHC.IO.Handle.Internals.html#initBufferState"><span class="hs-identifier hs-var">initBufferState</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547967"><span class="hs-identifier hs-var">ha_type</span></a></span><span>
</span><span id="line-665"></span><span>   </span><span class="hs-glyph">!</span><span id="local-6989586621679547945"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547945"><span class="hs-identifier hs-var">bbuf_no_offset</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">dev -&gt; BufferState -&gt; IO (Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; BufferState -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#newBuffer"><span class="hs-identifier hs-var">Buffered.newBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547969"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679547946"><span class="hs-identifier hs-var">buf_state</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-666"></span><span>   </span><span class="hs-glyph">!</span><span id="local-6989586621679547943"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679547943"><span class="hs-identifier hs-var">buf_offset</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO Word64
</span><a href="#local-6989586621679547942"><span class="hs-identifier hs-var">initHandleOffset</span></a></span><span>
</span><span id="line-667"></span><span>   </span><span class="hs-keyword">let</span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679547941"><span class="annot"><span class="annottext">bbuf :: Buffer Word8
</span><a href="#local-6989586621679547941"><span class="hs-identifier hs-var hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547945"><span class="hs-identifier hs-var">bbuf_no_offset</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679547943"><span class="hs-identifier hs-var">buf_offset</span></a></span><span class="hs-special">}</span><span>
</span><span id="line-668"></span><span>
</span><span id="line-669"></span><span>   </span><span id="local-6989586621679547940"><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547940"><span class="hs-identifier hs-var">bbufref</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (IORef (Buffer Word8))
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547941"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-670"></span><span>   </span><span id="local-6989586621679547939"><span class="annot"><span class="annottext">IORef (ds, Buffer Word8)
</span><a href="#local-6989586621679547939"><span class="hs-identifier hs-var">last_decode</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(ds, Buffer Word8) -&gt; IO (IORef (ds, Buffer Word8))
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; ds
forall a. FilePath -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;codec_state&quot;</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547941"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-671"></span><span>
</span><span id="line-672"></span><span>   </span><span class="hs-special">(</span><span id="local-6989586621679547937"><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679547937"><span class="hs-identifier hs-var">cbufref</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547936"><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679547936"><span class="hs-identifier hs-var">bmode</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-673"></span><span>         </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679547966"><span class="hs-identifier hs-var">buffered</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">dev -&gt; BufferState -&gt; IO (IORef (Buffer Char), BufferMode)
forall dev.
IODevice dev =&gt;
dev -&gt; BufferState -&gt; IO (IORef (Buffer Char), BufferMode)
</span><a href="GHC.IO.Handle.Internals.html#getCharBuffer"><span class="hs-identifier hs-var">getCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547969"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679547946"><span class="hs-identifier hs-var">buf_state</span></a></span><span>
</span><span id="line-674"></span><span>                     </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">BufferState -&gt; IO (IORef (Buffer Char), BufferMode)
</span><a href="GHC.IO.Handle.Internals.html#mkUnBuffer"><span class="hs-identifier hs-var">mkUnBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="#local-6989586621679547946"><span class="hs-identifier hs-var">buf_state</span></a></span><span>
</span><span id="line-675"></span><span>
</span><span id="line-676"></span><span>   </span><span id="local-6989586621679547935"><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679547935"><span class="hs-identifier hs-var">spares</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">BufferList Char -&gt; IO (IORef (BufferList Char))
forall a. a -&gt; IO (IORef a)
</span><a href="GHC.IORef.html#newIORef"><span class="hs-identifier hs-var">newIORef</span></a></span><span> </span><span class="annot"><span class="annottext">BufferList Char
forall e. BufferList e
</span><a href="GHC.IO.Handle.Types.html#BufferListNil"><span class="hs-identifier hs-var">BufferListNil</span></a></span><span>
</span><span id="line-677"></span><span>   </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(FilePath -&gt; IO ()) -&gt; FilePath -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;making handle for &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547968"><span class="hs-identifier hs-var">filepath</span></a></span><span>
</span><span id="line-678"></span><span>   </span><span class="annot"><span class="annottext">FilePath -&gt; Maybe HandleFinalizer -&gt; Handle__ -&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#newFileHandle"><span class="hs-identifier hs-var">newFileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547968"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe HandleFinalizer
</span><a href="#local-6989586621679547963"><span class="hs-identifier hs-var">finalizer</span></a></span><span>
</span><span id="line-679"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__ :: forall dev enc_state dec_state.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; HandleType
-&gt; IORef (Buffer Word8)
-&gt; BufferMode
-&gt; IORef (dec_state, Buffer Word8)
-&gt; IORef (Buffer Char)
-&gt; IORef (BufferList Char)
-&gt; Maybe (TextEncoder enc_state)
-&gt; Maybe (TextDecoder dec_state)
-&gt; Maybe TextEncoding
-&gt; Newline
-&gt; Newline
-&gt; Maybe (MVar Handle__)
-&gt; Handle__
</span><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">haDevice :: dev
</span><a href="GHC.IO.Handle.Types.html#haDevice"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547969"><span class="hs-identifier hs-var">dev</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-680"></span><span>                        </span><span class="annot"><span class="annottext">haType :: HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var">haType</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547967"><span class="hs-identifier hs-var">ha_type</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-681"></span><span>                        </span><span class="annot"><span class="annottext">haBufferMode :: BufferMode
</span><a href="GHC.IO.Handle.Types.html#haBufferMode"><span class="hs-identifier hs-var">haBufferMode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679547936"><span class="hs-identifier hs-var">bmode</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-682"></span><span>                        </span><span class="annot"><span class="annottext">haByteBuffer :: IORef (Buffer Word8)
</span><a href="GHC.IO.Handle.Types.html#haByteBuffer"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547940"><span class="hs-identifier hs-var">bbufref</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-683"></span><span>                        </span><span class="annot"><span class="annottext">haLastDecode :: IORef (ds, Buffer Word8)
</span><a href="GHC.IO.Handle.Types.html#haLastDecode"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef (ds, Buffer Word8)
</span><a href="#local-6989586621679547939"><span class="hs-identifier hs-var">last_decode</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-684"></span><span>                        </span><span class="annot"><span class="annottext">haCharBuffer :: IORef (Buffer Char)
</span><a href="GHC.IO.Handle.Types.html#haCharBuffer"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679547937"><span class="hs-identifier hs-var">cbufref</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-685"></span><span>                        </span><span class="annot"><span class="annottext">haBuffers :: IORef (BufferList Char)
</span><a href="GHC.IO.Handle.Types.html#haBuffers"><span class="hs-identifier hs-var">haBuffers</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679547935"><span class="hs-identifier hs-var">spares</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-686"></span><span>                        </span><span class="annot"><span class="annottext">haEncoder :: Maybe (TextEncoder es)
</span><a href="GHC.IO.Handle.Types.html#haEncoder"><span class="hs-identifier hs-var">haEncoder</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder es)
</span><a href="#local-6989586621679547948"><span class="hs-identifier hs-var">mb_encoder</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-687"></span><span>                        </span><span class="annot"><span class="annottext">haDecoder :: Maybe (TextDecoder ds)
</span><a href="GHC.IO.Handle.Types.html#haDecoder"><span class="hs-identifier hs-var">haDecoder</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder ds)
</span><a href="#local-6989586621679547947"><span class="hs-identifier hs-var">mb_decoder</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-688"></span><span>                        </span><span class="annot"><span class="annottext">haCodec :: Maybe TextEncoding
</span><a href="GHC.IO.Handle.Types.html#haCodec"><span class="hs-identifier hs-var">haCodec</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547965"><span class="hs-identifier hs-var">mb_codec</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-689"></span><span>                        </span><span class="annot"><span class="annottext">haInputNL :: Newline
</span><a href="GHC.IO.Handle.Types.html#haInputNL"><span class="hs-identifier hs-var">haInputNL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NewlineMode -&gt; Newline
</span><a href="GHC.IO.Handle.Types.html#inputNL"><span class="hs-identifier hs-var hs-var">inputNL</span></a></span><span> </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547964"><span class="hs-identifier hs-var">nl</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-690"></span><span>                        </span><span class="annot"><span class="annottext">haOutputNL :: Newline
</span><a href="GHC.IO.Handle.Types.html#haOutputNL"><span class="hs-identifier hs-var">haOutputNL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NewlineMode -&gt; Newline
</span><a href="GHC.IO.Handle.Types.html#outputNL"><span class="hs-identifier hs-var hs-var">outputNL</span></a></span><span> </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547964"><span class="hs-identifier hs-var">nl</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-691"></span><span>                        </span><span class="annot"><span class="annottext">haOtherSide :: Maybe (MVar Handle__)
</span><a href="GHC.IO.Handle.Types.html#haOtherSide"><span class="hs-identifier hs-var">haOtherSide</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
</span><a href="#local-6989586621679547962"><span class="hs-identifier hs-var">other_side</span></a></span><span>
</span><span id="line-692"></span><span>                      </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-693"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-694"></span><span>    </span><span class="hs-comment">-- See Note [Making offsets for append]</span><span>
</span><span id="line-695"></span><span>    </span><span id="local-6989586621679547942"><span class="annot"><span class="annottext">initHandleOffset :: IO Word64
</span><a href="#local-6989586621679547942"><span class="hs-identifier hs-var hs-var">initHandleOffset</span></a></span></span><span>
</span><span id="line-696"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">HandleType -&gt; Bool
</span><a href="GHC.IO.Handle.Types.html#isAppendHandleType"><span class="hs-identifier hs-var">isAppendHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547967"><span class="hs-identifier hs-var">ha_type</span></a></span><span>
</span><span id="line-697"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.SubSystem.html#isWindowsNativeIO"><span class="hs-identifier hs-var">isWindowsNativeIO</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-698"></span><span>          </span><span id="local-6989586621679547922"><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679547922"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; IO Integer
forall a. IODevice a =&gt; a -&gt; IO Integer
</span><a href="GHC.IO.Device.html#getSize"><span class="hs-identifier hs-var">IODevice.getSize</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547969"><span class="hs-identifier hs-var">dev</span></a></span><span>
</span><span id="line-699"></span><span>          </span><span class="annot"><span class="annottext">Word64 -&gt; IO Word64
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Integer -&gt; Word64
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Integer
</span><a href="#local-6989586621679547922"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-700"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; IO Word64
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Word64
</span><span class="hs-number">0</span></span><span>
</span><span id="line-701"></span><span>
</span><span id="line-702"></span><span class="hs-comment">-- | makes a new 'Handle'</span><span>
</span><span id="line-703"></span><span id="local-6989586621679548668"><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkFileHandle"><span class="hs-identifier hs-type">mkFileHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548668"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#IODevice"><span class="hs-identifier hs-type">IODevice</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548668"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html#BufferedIO"><span class="hs-identifier hs-type">BufferedIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548668"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Typeable.Internal.html#Typeable"><span class="hs-identifier hs-type">Typeable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548668"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-704"></span><span>             </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679548668"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-comment">-- ^ the underlying IO device, which must support</span><span>
</span><span id="line-705"></span><span>                    </span><span class="hs-comment">-- 'IODevice', 'BufferedIO' and 'Typeable'</span><span>
</span><span id="line-706"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span>
</span><span id="line-707"></span><span>                    </span><span class="hs-comment">-- ^ a string describing the 'Handle', e.g. the file</span><span>
</span><span id="line-708"></span><span>                    </span><span class="hs-comment">-- path for a file.  Used in error messages.</span><span>
</span><span id="line-709"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span>
</span><span id="line-710"></span><span>                    </span><span class="hs-comment">-- The mode in which the 'Handle' is to be used</span><span>
</span><span id="line-711"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span>
</span><span id="line-712"></span><span>                    </span><span class="hs-comment">-- Create the 'Handle' with no text encoding?</span><span>
</span><span id="line-713"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#NewlineMode"><span class="hs-identifier hs-type">NewlineMode</span></a></span><span>
</span><span id="line-714"></span><span>                    </span><span class="hs-comment">-- Translate newlines?</span><span>
</span><span id="line-715"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span></span><span>
</span><span id="line-716"></span><span id="mkFileHandle"><span class="annot"><span class="annottext">mkFileHandle :: forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; IOMode
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkFileHandle"><span class="hs-identifier hs-var hs-var">mkFileHandle</span></a></span></span><span> </span><span id="local-6989586621679547912"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547912"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679547911"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547911"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679547910"><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679547910"><span class="hs-identifier hs-var">iomode</span></a></span></span><span> </span><span id="local-6989586621679547909"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547909"><span class="hs-identifier hs-var">mb_codec</span></a></span></span><span> </span><span id="local-6989586621679547908"><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547908"><span class="hs-identifier hs-var">tr_newlines</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-717"></span><span>   </span><span class="annot"><span class="annottext">dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var">mkHandle</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547912"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547911"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOMode -&gt; HandleType
</span><a href="GHC.IO.Handle.Internals.html#ioModeToHandleType"><span class="hs-identifier hs-var">ioModeToHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="#local-6989586621679547910"><span class="hs-identifier hs-var">iomode</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-comment">{-buffered-}</span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547909"><span class="hs-identifier hs-var">mb_codec</span></a></span><span>
</span><span id="line-718"></span><span>            </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547908"><span class="hs-identifier hs-var">tr_newlines</span></a></span><span>
</span><span id="line-719"></span><span>            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HandleFinalizer -&gt; Maybe HandleFinalizer
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="GHC.IO.Handle.Internals.html#handleFinalizer"><span class="hs-identifier hs-var">handleFinalizer</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-comment">{-other_side-}</span><span>
</span><span id="line-720"></span><span>
</span><span id="line-721"></span><span class="hs-comment">-- | like 'mkFileHandle', except that a 'Handle' is created with two</span><span>
</span><span id="line-722"></span><span class="hs-comment">-- independent buffers, one for reading and one for writing.  Used for</span><span>
</span><span id="line-723"></span><span class="hs-comment">-- full-duplex streams, such as network sockets.</span><span>
</span><span id="line-724"></span><span id="local-6989586621679548665"><span class="annot"><a href="GHC.IO.Handle.Internals.html#mkDuplexHandle"><span class="hs-identifier hs-type">mkDuplexHandle</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548665"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#IODevice"><span class="hs-identifier hs-type">IODevice</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548665"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html#BufferedIO"><span class="hs-identifier hs-type">BufferedIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548665"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Typeable.Internal.html#Typeable"><span class="hs-identifier hs-type">Typeable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548665"><span class="hs-identifier hs-type">dev</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679548665"><span class="hs-identifier hs-type">dev</span></a></span><span>
</span><span id="line-725"></span><span>               </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.html#FilePath"><span class="hs-identifier hs-type">FilePath</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#NewlineMode"><span class="hs-identifier hs-type">NewlineMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span></span><span>
</span><span id="line-726"></span><span id="mkDuplexHandle"><span class="annot"><span class="annottext">mkDuplexHandle :: forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev -&gt; FilePath -&gt; Maybe TextEncoding -&gt; NewlineMode -&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkDuplexHandle"><span class="hs-identifier hs-var hs-var">mkDuplexHandle</span></a></span></span><span> </span><span id="local-6989586621679547888"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547888"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679547887"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547887"><span class="hs-identifier hs-var">filepath</span></a></span></span><span> </span><span id="local-6989586621679547886"><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547886"><span class="hs-identifier hs-var">mb_codec</span></a></span></span><span> </span><span id="local-6989586621679547885"><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547885"><span class="hs-identifier hs-var">tr_newlines</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-727"></span><span>
</span><span id="line-728"></span><span>  </span><span id="local-6989586621679547884"><span class="annot"><span class="annottext">write_side :: Handle
</span><a href="#local-6989586621679547884"><span class="hs-identifier hs-var">write_side</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679547883"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679547883"><span class="hs-identifier hs-var">write_m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-729"></span><span>       </span><span class="annot"><span class="annottext">dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var">mkHandle</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547888"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547887"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#WriteHandle"><span class="hs-identifier hs-var">WriteHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547886"><span class="hs-identifier hs-var">mb_codec</span></a></span><span>
</span><span id="line-730"></span><span>                        </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547885"><span class="hs-identifier hs-var">tr_newlines</span></a></span><span>
</span><span id="line-731"></span><span>                        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">HandleFinalizer -&gt; Maybe HandleFinalizer
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">HandleFinalizer
</span><a href="GHC.IO.Handle.Internals.html#handleFinalizer"><span class="hs-identifier hs-var">handleFinalizer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-732"></span><span>                        </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-comment">-- no othersie</span><span>
</span><span id="line-733"></span><span>
</span><span id="line-734"></span><span>  </span><span id="local-6989586621679547882"><span class="annot"><span class="annottext">read_side :: Handle
</span><a href="#local-6989586621679547882"><span class="hs-identifier hs-var">read_side</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#FileHandle"><span class="hs-identifier hs-type">FileHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679547881"><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679547881"><span class="hs-identifier hs-var">read_m</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-735"></span><span>      </span><span class="annot"><span class="annottext">dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
forall dev.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; FilePath
-&gt; HandleType
-&gt; Bool
-&gt; Maybe TextEncoding
-&gt; NewlineMode
-&gt; Maybe HandleFinalizer
-&gt; Maybe (MVar Handle__)
-&gt; IO Handle
</span><a href="GHC.IO.Handle.Internals.html#mkHandle"><span class="hs-identifier hs-var">mkHandle</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547888"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547887"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadHandle"><span class="hs-identifier hs-var">ReadHandle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="#local-6989586621679547886"><span class="hs-identifier hs-var">mb_codec</span></a></span><span>
</span><span id="line-736"></span><span>                        </span><span class="annot"><span class="annottext">NewlineMode
</span><a href="#local-6989586621679547885"><span class="hs-identifier hs-var">tr_newlines</span></a></span><span>
</span><span id="line-737"></span><span>                        </span><span class="annot"><span class="annottext">Maybe HandleFinalizer
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-comment">-- no finalizer</span><span>
</span><span id="line-738"></span><span>                        </span><span class="hs-special">(</span><span class="annot"><span class="annottext">MVar Handle__ -&gt; Maybe (MVar Handle__)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679547883"><span class="hs-identifier hs-var">write_m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-739"></span><span>
</span><span id="line-740"></span><span>  </span><span class="annot"><span class="annottext">Handle -&gt; IO Handle
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; MVar Handle__ -&gt; MVar Handle__ -&gt; Handle
</span><a href="GHC.IO.Handle.Types.html#DuplexHandle"><span class="hs-identifier hs-var">DuplexHandle</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547887"><span class="hs-identifier hs-var">filepath</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679547881"><span class="hs-identifier hs-var">read_m</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><a href="#local-6989586621679547883"><span class="hs-identifier hs-var">write_m</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-741"></span><span>
</span><span id="line-742"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioModeToHandleType"><span class="hs-identifier hs-type">ioModeToHandleType</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.IOMode.html#IOMode"><span class="hs-identifier hs-type">IOMode</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#HandleType"><span class="hs-identifier hs-type">HandleType</span></a></span><span>
</span><span id="line-743"></span><span id="ioModeToHandleType"><span class="annot"><span class="annottext">ioModeToHandleType :: IOMode -&gt; HandleType
</span><a href="GHC.IO.Handle.Internals.html#ioModeToHandleType"><span class="hs-identifier hs-var hs-var">ioModeToHandleType</span></a></span></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadMode"><span class="hs-identifier hs-var">ReadMode</span></a></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadHandle"><span class="hs-identifier hs-var">ReadHandle</span></a></span><span>
</span><span id="line-744"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioModeToHandleType"><span class="hs-identifier hs-var">ioModeToHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#WriteMode"><span class="hs-identifier hs-var">WriteMode</span></a></span><span>     </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#WriteHandle"><span class="hs-identifier hs-var">WriteHandle</span></a></span><span>
</span><span id="line-745"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioModeToHandleType"><span class="hs-identifier hs-var">ioModeToHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#ReadWriteMode"><span class="hs-identifier hs-var">ReadWriteMode</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadWriteHandle"><span class="hs-identifier hs-var">ReadWriteHandle</span></a></span><span>
</span><span id="line-746"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#ioModeToHandleType"><span class="hs-identifier hs-var">ioModeToHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">IOMode
</span><a href="GHC.IO.IOMode.html#AppendMode"><span class="hs-identifier hs-var">AppendMode</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#AppendHandle"><span class="hs-identifier hs-var">AppendHandle</span></a></span><span>
</span><span id="line-747"></span><span>
</span><span id="line-748"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#initBufferState"><span class="hs-identifier hs-type">initBufferState</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#HandleType"><span class="hs-identifier hs-type">HandleType</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#BufferState"><span class="hs-identifier hs-type">BufferState</span></a></span><span>
</span><span id="line-749"></span><span id="initBufferState"><span class="annot"><span class="annottext">initBufferState :: HandleType -&gt; BufferState
</span><a href="GHC.IO.Handle.Internals.html#initBufferState"><span class="hs-identifier hs-var hs-var">initBufferState</span></a></span></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ReadHandle"><span class="hs-identifier hs-var">ReadHandle</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>
</span><span id="line-750"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#initBufferState"><span class="hs-identifier hs-var">initBufferState</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><span class="hs-identifier">_</span></span><span>          </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span>
</span><span id="line-751"></span><span>
</span><span id="line-752"></span><span id="local-6989586621679548677"><span class="annot"><a href="GHC.IO.Handle.Internals.html#openTextEncoding"><span class="hs-identifier hs-type">openTextEncoding</span></a></span><span>
</span><span id="line-753"></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span>
</span><span id="line-754"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#HandleType"><span class="hs-identifier hs-type">HandleType</span></a></span><span>
</span><span id="line-755"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">forall</span><span> </span><span id="local-6989586621679548679"><span class="annot"><a href="#local-6989586621679548679"><span class="hs-identifier hs-type">es</span></a></span></span><span> </span><span id="local-6989586621679548678"><span class="annot"><a href="#local-6989586621679548678"><span class="hs-identifier hs-type">ds</span></a></span></span><span> </span><span class="hs-operator">.</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoder"><span class="hs-identifier hs-type">TextEncoder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548679"><span class="hs-identifier hs-type">es</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextDecoder"><span class="hs-identifier hs-type">TextDecoder</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548678"><span class="hs-identifier hs-type">ds</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548677"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-756"></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679548677"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-757"></span><span>
</span><span id="line-758"></span><span id="openTextEncoding"><span class="annot"><span class="annottext">openTextEncoding :: forall a.
Maybe TextEncoding
-&gt; HandleType
-&gt; (forall es ds.
    Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO a)
-&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#openTextEncoding"><span class="hs-identifier hs-var hs-var">openTextEncoding</span></a></span></span><span> </span><span class="annot"><span class="annottext">Maybe TextEncoding
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>   </span><span id="local-6989586621679547876"><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547876"><span class="hs-identifier hs-var">ha_type</span></a></span></span><span> </span><span id="local-6989586621679547875"><span class="annot"><span class="annottext">forall es ds.
Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO a
</span><a href="#local-6989586621679547875"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder Any) -&gt; Maybe (TextDecoder Any) -&gt; IO a
forall es ds.
Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO a
</span><a href="#local-6989586621679547875"><span class="hs-identifier hs-var">cont</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder Any)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder Any)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-759"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#openTextEncoding"><span class="hs-identifier hs-var">openTextEncoding</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Encoding.Types.html#TextEncoding"><span class="hs-identifier hs-type">TextEncoding</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547863"><span id="local-6989586621679547864"><span id="local-6989586621679547865"><span class="annot"><span class="annottext">FilePath
IO (TextEncoder estate)
IO (TextDecoder dstate)
textEncodingName :: TextEncoding -&gt; FilePath
mkTextEncoder :: ()
mkTextDecoder :: ()
mkTextEncoder :: IO (TextEncoder estate)
mkTextDecoder :: IO (TextDecoder dstate)
textEncodingName :: FilePath
</span><a href="GHC.IO.Encoding.Types.html#textEncodingName"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span><span class="hs-special">}</span><span class="hs-special">)</span><span> </span><span id="local-6989586621679547859"><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547859"><span class="hs-identifier hs-var">ha_type</span></a></span></span><span> </span><span id="local-6989586621679547858"><span class="annot"><span class="annottext">forall es ds.
Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO a
</span><a href="#local-6989586621679547858"><span class="hs-identifier hs-var">cont</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-760"></span><span>    </span><span id="local-6989586621679547857"><span class="annot"><span class="annottext">Maybe (TextDecoder dstate)
</span><a href="#local-6989586621679547857"><span class="hs-identifier hs-var">mb_decoder</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">HandleType -&gt; Bool
</span><a href="GHC.IO.Handle.Types.html#isReadableHandleType"><span class="hs-identifier hs-var">isReadableHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547859"><span class="hs-identifier hs-var">ha_type</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-761"></span><span>                     </span><span id="local-6989586621679547855"><span class="annot"><span class="annottext">TextDecoder dstate
</span><a href="#local-6989586621679547855"><span class="hs-identifier hs-var">decoder</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (TextDecoder dstate)
</span><a href="#local-6989586621679547864"><span class="hs-identifier hs-var">mkTextDecoder</span></a></span><span>
</span><span id="line-762"></span><span>                     </span><span class="annot"><span class="annottext">Maybe (TextDecoder dstate) -&gt; IO (Maybe (TextDecoder dstate))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextDecoder dstate -&gt; Maybe (TextDecoder dstate)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dstate
</span><a href="#local-6989586621679547855"><span class="hs-identifier hs-var">decoder</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-763"></span><span>                  </span><span class="hs-keyword">else</span><span>
</span><span id="line-764"></span><span>                     </span><span class="annot"><span class="annottext">Maybe (TextDecoder dstate) -&gt; IO (Maybe (TextDecoder dstate))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dstate)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-765"></span><span>    </span><span id="local-6989586621679547854"><span class="annot"><span class="annottext">Maybe (TextEncoder estate)
</span><a href="#local-6989586621679547854"><span class="hs-identifier hs-var">mb_encoder</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">HandleType -&gt; Bool
</span><a href="GHC.IO.Handle.Types.html#isWritableHandleType"><span class="hs-identifier hs-var">isWritableHandleType</span></a></span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="#local-6989586621679547859"><span class="hs-identifier hs-var">ha_type</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-766"></span><span>                     </span><span id="local-6989586621679547852"><span class="annot"><span class="annottext">TextEncoder estate
</span><a href="#local-6989586621679547852"><span class="hs-identifier hs-var">encoder</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (TextEncoder estate)
</span><a href="#local-6989586621679547863"><span class="hs-identifier hs-var">mkTextEncoder</span></a></span><span>
</span><span id="line-767"></span><span>                     </span><span class="annot"><span class="annottext">Maybe (TextEncoder estate) -&gt; IO (Maybe (TextEncoder estate))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextEncoder estate -&gt; Maybe (TextEncoder estate)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoder estate
</span><a href="#local-6989586621679547852"><span class="hs-identifier hs-var">encoder</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-768"></span><span>                  </span><span class="hs-keyword">else</span><span>
</span><span id="line-769"></span><span>                     </span><span class="annot"><span class="annottext">Maybe (TextEncoder estate) -&gt; IO (Maybe (TextEncoder estate))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder estate)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-770"></span><span>    </span><span class="annot"><span class="annottext">Maybe (TextEncoder estate) -&gt; Maybe (TextDecoder dstate) -&gt; IO a
forall es ds.
Maybe (TextEncoder es) -&gt; Maybe (TextDecoder ds) -&gt; IO a
</span><a href="#local-6989586621679547858"><span class="hs-identifier hs-var">cont</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder estate)
</span><a href="#local-6989586621679547854"><span class="hs-identifier hs-var">mb_encoder</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dstate)
</span><a href="#local-6989586621679547857"><span class="hs-identifier hs-var">mb_decoder</span></a></span><span>
</span><span id="line-771"></span><span>
</span><span id="line-772"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#closeTextCodecs"><span class="hs-identifier hs-type">closeTextCodecs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-773"></span><span id="closeTextCodecs"><span class="annot"><span class="annottext">closeTextCodecs :: Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#closeTextCodecs"><span class="hs-identifier hs-var hs-var">closeTextCodecs</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547832"><span id="local-6989586621679547833"><span id="local-6989586621679547834"><span id="local-6989586621679547835"><span id="local-6989586621679547836"><span id="local-6989586621679547837"><span id="local-6989586621679547838"><span id="local-6989586621679547839"><span id="local-6989586621679547840"><span id="local-6989586621679547841"><span id="local-6989586621679547842"><span id="local-6989586621679547843"><span id="local-6989586621679547844"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547832"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-774"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="#local-6989586621679547836"><span class="hs-identifier hs-var">haDecoder</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679547831"><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547831"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state -&gt; IO ()
forall from to state. BufferCodec from to state -&gt; IO ()
</span><a href="GHC.IO.Encoding.Types.html#close"><span class="hs-identifier hs-var hs-var">Encoding.close</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547831"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-775"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder enc_state)
</span><a href="#local-6989586621679547837"><span class="hs-identifier hs-var">haEncoder</span></a></span><span> </span><span class="hs-keyword">of</span><span> </span><span class="annot"><span class="annottext">Maybe (TextEncoder enc_state)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">;</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679547829"><span class="annot"><span class="annottext">TextEncoder enc_state
</span><a href="#local-6989586621679547829"><span class="hs-identifier hs-var">d</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TextEncoder enc_state -&gt; IO ()
forall from to state. BufferCodec from to state -&gt; IO ()
</span><a href="GHC.IO.Encoding.Types.html#close"><span class="hs-identifier hs-var hs-var">Encoding.close</span></a></span><span> </span><span class="annot"><span class="annottext">TextEncoder enc_state
</span><a href="#local-6989586621679547829"><span class="hs-identifier hs-var">d</span></a></span><span>
</span><span id="line-776"></span><span>
</span><span id="line-777"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-778"></span><span class="hs-comment">-- closing Handles</span><span>
</span><span id="line-779"></span><span>
</span><span id="line-780"></span><span class="hs-comment">-- hClose_help is also called by lazyRead (in GHC.IO.Handle.Text) when</span><span>
</span><span id="line-781"></span><span class="hs-comment">-- EOF is read or an IO error occurs on a lazy stream.  The</span><span>
</span><span id="line-782"></span><span class="hs-comment">-- semi-closed Handle is then closed immediately.  We have to be</span><span>
</span><span id="line-783"></span><span class="hs-comment">-- careful with DuplexHandles though: we have to leave the closing to</span><span>
</span><span id="line-784"></span><span class="hs-comment">-- the finalizer in that case, because the write side may still be in</span><span>
</span><span id="line-785"></span><span class="hs-comment">-- use.</span><span>
</span><span id="line-786"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#hClose_help"><span class="hs-identifier hs-type">hClose_help</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-787"></span><span id="hClose_help"><span class="annot"><span class="annottext">hClose_help :: Handle__ -&gt; IO (Handle__, Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#hClose_help"><span class="hs-identifier hs-var hs-var">hClose_help</span></a></span></span><span> </span><span id="local-6989586621679547828"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547828"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-788"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var hs-var">haType</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547828"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-789"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(Handle__, Maybe SomeException)
-&gt; IO (Handle__, Maybe SomeException)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547828"><span class="hs-identifier hs-var">handle_</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Maybe SomeException
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-790"></span><span>      </span><span class="annot"><span class="annottext">HandleType
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679547827"><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547827"><span class="hs-identifier hs-var">mb_exc1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO (Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#trymaybe"><span class="hs-identifier hs-var">trymaybe</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO (Maybe SomeException))
-&gt; IO () -&gt; IO (Maybe SomeException)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-var">flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547828"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="hs-comment">-- interruptible</span><span>
</span><span id="line-791"></span><span>                    </span><span class="hs-comment">-- it is important that hClose doesn't fail and</span><span>
</span><span id="line-792"></span><span>                    </span><span class="hs-comment">-- leave the Handle open (#3128), so we catch</span><span>
</span><span id="line-793"></span><span>                    </span><span class="hs-comment">-- exceptions when flushing the buffer.</span><span>
</span><span id="line-794"></span><span>              </span><span class="hs-special">(</span><span id="local-6989586621679547825"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547825"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679547824"><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547824"><span class="hs-identifier hs-var">mb_exc2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#hClose_handle_"><span class="hs-identifier hs-var">hClose_handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547828"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-795"></span><span>              </span><span class="annot"><span class="annottext">(Handle__, Maybe SomeException)
-&gt; IO (Handle__, Maybe SomeException)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547825"><span class="hs-identifier hs-var">h_</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="Data.Maybe.html#isJust"><span class="hs-identifier hs-var">isJust</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547827"><span class="hs-identifier hs-var">mb_exc1</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547827"><span class="hs-identifier hs-var">mb_exc1</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547824"><span class="hs-identifier hs-var">mb_exc2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-796"></span><span>
</span><span id="line-797"></span><span>
</span><span id="line-798"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#trymaybe"><span class="hs-identifier hs-type">trymaybe</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-799"></span><span id="trymaybe"><span class="annot"><span class="annottext">trymaybe :: IO () -&gt; IO (Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#trymaybe"><span class="hs-identifier hs-var hs-var">trymaybe</span></a></span></span><span> </span><span id="local-6989586621679547821"><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679547821"><span class="hs-identifier hs-var">io</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">IO ()
</span><a href="#local-6989586621679547821"><span class="hs-identifier hs-var">io</span></a></span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException -&gt; IO (Maybe SomeException)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IO (Maybe SomeException)
-&gt; (SomeException -&gt; IO (Maybe SomeException))
-&gt; IO (Maybe SomeException)
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-operator hs-var">`catchException`</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679547820"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679547820"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException -&gt; IO (Maybe SomeException)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SomeException -&gt; Maybe SomeException
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679547820"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-800"></span><span>
</span><span id="line-801"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#hClose_handle_"><span class="hs-identifier hs-type">hClose_handle_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-802"></span><span id="hClose_handle_"><span class="annot"><span class="annottext">hClose_handle_ :: Handle__ -&gt; IO (Handle__, Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#hClose_handle_"><span class="hs-identifier hs-var hs-var">hClose_handle_</span></a></span></span><span> </span><span id="local-6989586621679547819"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679547819"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547790"><span id="local-6989586621679547791"><span id="local-6989586621679547792"><span id="local-6989586621679547793"><span id="local-6989586621679547794"><span id="local-6989586621679547795"><span id="local-6989586621679547796"><span id="local-6989586621679547797"><span id="local-6989586621679547798"><span id="local-6989586621679547799"><span id="local-6989586621679547800"><span id="local-6989586621679547801"><span id="local-6989586621679547802"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547790"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-803"></span><span>
</span><span id="line-804"></span><span>    </span><span class="hs-comment">-- close the file descriptor, but not when this is the read</span><span>
</span><span id="line-805"></span><span>    </span><span class="hs-comment">-- side of a duplex handle.</span><span>
</span><span id="line-806"></span><span>    </span><span class="hs-comment">-- If an exception is raised by the close(), we want to continue</span><span>
</span><span id="line-807"></span><span>    </span><span class="hs-comment">-- to close the handle and release the lock if it has one, then</span><span>
</span><span id="line-808"></span><span>    </span><span class="hs-comment">-- we return the exception to the caller of hClose_help which can</span><span>
</span><span id="line-809"></span><span>    </span><span class="hs-comment">-- raise it if necessary.</span><span>
</span><span id="line-810"></span><span>    </span><span id="local-6989586621679547789"><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547789"><span class="hs-identifier hs-var">maybe_exception</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-811"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
</span><a href="#local-6989586621679547790"><span class="hs-identifier hs-var">haOtherSide</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-812"></span><span>        </span><span class="annot"><span class="annottext">Maybe (MVar Handle__)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO (Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#trymaybe"><span class="hs-identifier hs-var">trymaybe</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO (Maybe SomeException))
-&gt; IO () -&gt; IO (Maybe SomeException)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">dev -&gt; IO ()
forall a. IODevice a =&gt; a -&gt; IO ()
</span><a href="GHC.IO.Device.html#close"><span class="hs-identifier hs-var">IODevice.close</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547802"><span class="hs-identifier hs-var">haDevice</span></a></span><span>
</span><span id="line-813"></span><span>        </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">MVar Handle__
</span><span class="hs-identifier">_</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException -&gt; IO (Maybe SomeException)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-814"></span><span>
</span><span id="line-815"></span><span>    </span><span class="hs-comment">-- free the spare buffers</span><span>
</span><span id="line-816"></span><span>    </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; BufferList Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679547796"><span class="hs-identifier hs-var">haBuffers</span></a></span><span> </span><span class="annot"><span class="annottext">BufferList Char
forall e. BufferList e
</span><a href="GHC.IO.Handle.Types.html#BufferListNil"><span class="hs-identifier hs-var">BufferListNil</span></a></span><span>
</span><span id="line-817"></span><span>    </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679547797"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="GHC.IO.Handle.Internals.html#noCharBuffer"><span class="hs-identifier hs-var">noCharBuffer</span></a></span><span>
</span><span id="line-818"></span><span>    </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547800"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="GHC.IO.Handle.Internals.html#noByteBuffer"><span class="hs-identifier hs-var">noByteBuffer</span></a></span><span>
</span><span id="line-819"></span><span>
</span><span id="line-820"></span><span>    </span><span class="hs-comment">-- release our encoder/decoder</span><span>
</span><span id="line-821"></span><span>    </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#closeTextCodecs"><span class="hs-identifier hs-var">closeTextCodecs</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547819"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-822"></span><span>
</span><span id="line-823"></span><span>    </span><span class="hs-comment">-- we must set the fd to -1, because the finalizer is going</span><span>
</span><span id="line-824"></span><span>    </span><span class="hs-comment">-- to run eventually and try to close/unlock it.</span><span>
</span><span id="line-825"></span><span>    </span><span class="hs-comment">-- ToDo: necessary?  the handle will be marked ClosedHandle</span><span>
</span><span id="line-826"></span><span>    </span><span class="hs-comment">-- XXX GHC won't let us use record update here, hence wildcards</span><span>
</span><span id="line-827"></span><span>    </span><span class="annot"><span class="annottext">(Handle__, Maybe SomeException)
-&gt; IO (Handle__, Maybe SomeException)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__ :: forall dev enc_state dec_state.
(RawIO dev, IODevice dev, BufferedIO dev, Typeable dev) =&gt;
dev
-&gt; HandleType
-&gt; IORef (Buffer Word8)
-&gt; BufferMode
-&gt; IORef (dec_state, Buffer Word8)
-&gt; IORef (Buffer Char)
-&gt; IORef (BufferList Char)
-&gt; Maybe (TextEncoder enc_state)
-&gt; Maybe (TextDecoder dec_state)
-&gt; Maybe TextEncoding
-&gt; Newline
-&gt; Newline
-&gt; Maybe (MVar Handle__)
-&gt; Handle__
</span><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">haType :: HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var">haType</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haDevice :: dev
haOutputNL :: Newline
haOtherSide :: Maybe (MVar Handle__)
haLastDecode :: IORef (dec_state, Buffer Word8)
haInputNL :: Newline
haEncoder :: Maybe (TextEncoder enc_state)
haDevice :: dev
haDecoder :: Maybe (TextDecoder dec_state)
haCodec :: Maybe TextEncoding
haCharBuffer :: IORef (Buffer Char)
haByteBuffer :: IORef (Buffer Word8)
haBuffers :: IORef (BufferList Char)
haBufferMode :: BufferMode
</span><a href="#local-6989586621679547790"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679547789"><span class="hs-identifier hs-var">maybe_exception</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-828"></span><span>
</span><span id="line-829"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#noCharBuffer"><span class="hs-pragma hs-type">noCharBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-830"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#noCharBuffer"><span class="hs-identifier hs-type">noCharBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-831"></span><span id="noCharBuffer"><span class="annot"><span class="annottext">noCharBuffer :: Buffer Char
</span><a href="GHC.IO.Handle.Internals.html#noCharBuffer"><span class="hs-identifier hs-var hs-var">noCharBuffer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Buffer Char) -&gt; Buffer Char
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (Buffer Char) -&gt; Buffer Char)
-&gt; IO (Buffer Char) -&gt; Buffer Char
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-var">newCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>
</span><span id="line-832"></span><span>
</span><span id="line-833"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html#noByteBuffer"><span class="hs-pragma hs-type">noByteBuffer</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-834"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#noByteBuffer"><span class="hs-identifier hs-type">noByteBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span>
</span><span id="line-835"></span><span id="noByteBuffer"><span class="annot"><span class="annottext">noByteBuffer :: Buffer Word8
</span><a href="GHC.IO.Handle.Internals.html#noByteBuffer"><span class="hs-identifier hs-var hs-var">noByteBuffer</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Buffer Word8) -&gt; Buffer Word8
forall a. IO a -&gt; a
</span><a href="GHC.IO.Unsafe.html#unsafePerformIO"><span class="hs-identifier hs-var">unsafePerformIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO (Buffer Word8) -&gt; Buffer Word8)
-&gt; IO (Buffer Word8) -&gt; Buffer Word8
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Buffer.html#newByteBuffer"><span class="hs-identifier hs-var">newByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>
</span><span id="line-836"></span><span>
</span><span id="line-837"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-838"></span><span class="hs-comment">-- Looking ahead</span><span>
</span><span id="line-839"></span><span>
</span><span id="line-840"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#hLookAhead_"><span class="hs-identifier hs-type">hLookAhead_</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-841"></span><span id="hLookAhead_"><span class="annot"><span class="annottext">hLookAhead_ :: Handle__ -&gt; IO Char
</span><a href="GHC.IO.Handle.Internals.html#hLookAhead_"><span class="hs-identifier hs-var hs-var">hLookAhead_</span></a></span></span><span> </span><span id="local-6989586621679547783"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679547783"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547762"><span id="local-6989586621679547763"><span id="local-6989586621679547764"><span id="local-6989586621679547765"><span id="local-6989586621679547766"><span id="local-6989586621679547767"><span id="local-6989586621679547768"><span id="local-6989586621679547769"><span id="local-6989586621679547770"><span id="local-6989586621679547771"><span id="local-6989586621679547772"><span id="local-6989586621679547773"><span id="local-6989586621679547774"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547762"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-842"></span><span>    </span><span id="local-6989586621679547761"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547761"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679547769"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-843"></span><span>
</span><span id="line-844"></span><span>    </span><span class="hs-comment">-- fill up the read buffer if necessary</span><span>
</span><span id="line-845"></span><span>    </span><span id="local-6989586621679547760"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547760"><span class="hs-identifier hs-var">new_buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547761"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-846"></span><span>                  </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547783"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547761"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-847"></span><span>                  </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547761"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-848"></span><span>    </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679547769"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547760"><span class="hs-identifier hs-var">new_buf</span></a></span><span>
</span><span id="line-849"></span><span>
</span><span id="line-850"></span><span>    </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO Char
</span><a href="GHC.IO.Buffer.html#peekCharBuf"><span class="hs-identifier hs-var">peekCharBuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; RawCharBuffer
forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547761"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547761"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-851"></span><span>
</span><span id="line-852"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-853"></span><span class="hs-comment">-- debugging</span><span>
</span><span id="line-854"></span><span>
</span><span id="line-855"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-type">debugIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-856"></span><span class="hs-comment">-- debugIO s = traceEventIO s</span><span>
</span><span id="line-857"></span><span id="debugIO"><span class="annot"><span class="annottext">debugIO :: FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var hs-var">debugIO</span></a></span></span><span> </span><span id="local-6989586621679547757"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547757"><span class="hs-identifier hs-var">s</span></a></span></span><span>
</span><span id="line-858"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.IO.Handle.Internals.html#c_DEBUG_DUMP"><span class="hs-identifier hs-var">c_DEBUG_DUMP</span></a></span><span>
</span><span id="line-859"></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; (CStringLen -&gt; IO CInt) -&gt; IO CInt
forall a. FilePath -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCStringLen"><span class="hs-identifier hs-var">withCStringLen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547757"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;\n&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((CStringLen -&gt; IO CInt) -&gt; IO CInt)
-&gt; (CStringLen -&gt; IO CInt) -&gt; IO CInt
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-860"></span><span>                  </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621679547755"><span class="annot"><span class="annottext">Ptr CChar
</span><a href="#local-6989586621679547755"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679547754"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547754"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; Ptr Word8 -&gt; CUInt -&gt; IO CInt
</span><a href="System.Posix.Internals.html#c_write"><span class="hs-identifier hs-var">c_write</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">1</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr CChar -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CChar
</span><a href="#local-6989586621679547755"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CUInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547754"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-861"></span><span>         </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-862"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-863"></span><span>
</span><span id="line-864"></span><span class="hs-comment">-- For development, like debugIO but always on.</span><span>
</span><span id="line-865"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#traceIO"><span class="hs-identifier hs-type">traceIO</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-866"></span><span id="traceIO"><span class="annot"><span class="annottext">traceIO :: FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#traceIO"><span class="hs-identifier hs-var hs-var">traceIO</span></a></span></span><span> </span><span id="local-6989586621679547751"><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547751"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-867"></span><span>         </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; (CStringLen -&gt; IO CInt) -&gt; IO CInt
forall a. FilePath -&gt; (CStringLen -&gt; IO a) -&gt; IO a
</span><a href="Foreign.C.String.html#withCStringLen"><span class="hs-identifier hs-var">withCStringLen</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><a href="#local-6989586621679547751"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;\n&quot;</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">((CStringLen -&gt; IO CInt) -&gt; IO CInt)
-&gt; (CStringLen -&gt; IO CInt) -&gt; IO CInt
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-868"></span><span>                  </span><span class="hs-glyph">\</span><span class="hs-special">(</span><span id="local-6989586621679547750"><span class="annot"><span class="annottext">Ptr CChar
</span><a href="#local-6989586621679547750"><span class="hs-identifier hs-var">p</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679547749"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547749"><span class="hs-identifier hs-var">len</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">CInt -&gt; Ptr Word8 -&gt; CUInt -&gt; IO CInt
</span><a href="System.Posix.Internals.html#c_write"><span class="hs-identifier hs-var">c_write</span></a></span><span> </span><span class="annot"><span class="annottext">CInt
</span><span class="hs-number">1</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr CChar -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr CChar
</span><a href="#local-6989586621679547750"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CUInt
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547749"><span class="hs-identifier hs-var">len</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-869"></span><span>         </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-870"></span><span>
</span><span id="line-871"></span><span class="hs-comment">-- ----------------------------------------------------------------------------</span><span>
</span><span id="line-872"></span><span class="hs-comment">-- Text input/output</span><span>
</span><span id="line-873"></span><span>
</span><span id="line-874"></span><span class="hs-comment">-- Read characters into the provided buffer.  Return when any</span><span>
</span><span id="line-875"></span><span class="hs-comment">-- characters are available; raise an exception if the end of</span><span>
</span><span id="line-876"></span><span class="hs-comment">-- file is reached.</span><span>
</span><span id="line-877"></span><span class="hs-comment">--</span><span>
</span><span id="line-878"></span><span class="hs-comment">-- In uses of readTextDevice within base, the input buffer is either:</span><span>
</span><span id="line-879"></span><span class="hs-comment">--   * empty</span><span>
</span><span id="line-880"></span><span class="hs-comment">--   * or contains a single \r (when doing newline translation)</span><span>
</span><span id="line-881"></span><span class="hs-comment">--</span><span>
</span><span id="line-882"></span><span class="hs-comment">-- The input character buffer must have a capacity at least 1 greater</span><span>
</span><span id="line-883"></span><span class="hs-comment">-- than the number of elements it currently contains.</span><span>
</span><span id="line-884"></span><span class="hs-comment">--</span><span>
</span><span id="line-885"></span><span class="hs-comment">-- Users of this function expect that the buffer returned contains</span><span>
</span><span id="line-886"></span><span class="hs-comment">-- at least 1 more character than the input buffer.</span><span>
</span><span id="line-887"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-type">readTextDevice</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-888"></span><span id="readTextDevice"><span class="annot"><span class="annottext">readTextDevice :: Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var hs-var">readTextDevice</span></a></span></span><span> </span><span id="local-6989586621679547748"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679547748"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547708"><span id="local-6989586621679547709"><span id="local-6989586621679547710"><span id="local-6989586621679547711"><span id="local-6989586621679547712"><span id="local-6989586621679547713"><span id="local-6989586621679547714"><span id="local-6989586621679547715"><span id="local-6989586621679547716"><span id="local-6989586621679547717"><span id="local-6989586621679547718"><span id="local-6989586621679547719"><span id="local-6989586621679547720"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547708"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679547707"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547707"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-889"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-890"></span><span>  </span><span id="local-6989586621679547706"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547706"><span class="hs-identifier hs-var">bbuf0</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547718"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-891"></span><span>
</span><span id="line-892"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readTextDevice: cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547707"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span>
</span><span id="line-893"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot; bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547706"><span class="hs-identifier hs-var">bbuf0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-894"></span><span>
</span><span id="line-895"></span><span>  </span><span id="local-6989586621679547705"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547705"><span class="hs-identifier hs-var">bbuf1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547706"><span class="hs-identifier hs-var">bbuf0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-896"></span><span>              </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547706"><span class="hs-identifier hs-var">bbuf0</span></a></span><span>
</span><span id="line-897"></span><span>              </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-898"></span><span>                   </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(FilePath -&gt; IO ()) -&gt; FilePath -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readBuf at &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; FilePath
forall a. Show a =&gt; a -&gt; FilePath
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var">bufferOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547706"><span class="hs-identifier hs-var">bbuf0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-899"></span><span>                   </span><span class="hs-special">(</span><span id="local-6989586621679547703"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547703"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547702"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547702"><span class="hs-identifier hs-var">bbuf1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#fillReadBuffer"><span class="hs-identifier hs-var">Buffered.fillReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547720"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547706"><span class="hs-identifier hs-var">bbuf0</span></a></span><span>
</span><span id="line-900"></span><span>                   </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(FilePath -&gt; IO ()) -&gt; FilePath -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readBuf after &quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; FilePath
forall a. Show a =&gt; a -&gt; FilePath
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufferOffset"><span class="hs-identifier hs-var">bufferOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547702"><span class="hs-identifier hs-var">bbuf1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-901"></span><span>                   </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547703"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">IO (Buffer Word8)
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier hs-var">ioe_EOF</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-comment">-- raise EOF</span><span>
</span><span id="line-902"></span><span>                   </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547702"><span class="hs-identifier hs-var">bbuf1</span></a></span><span>
</span><span id="line-903"></span><span>
</span><span id="line-904"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readTextDevice after reading: bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547705"><span class="hs-identifier hs-var">bbuf1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-905"></span><span>
</span><span id="line-906"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679547700"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547700"><span class="hs-identifier hs-var">bbuf2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547699"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547699"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-907"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="#local-6989586621679547712"><span class="hs-identifier hs-var">haDecoder</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-908"></span><span>          </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-909"></span><span>               </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
-&gt; (dec_state, Buffer Word8) -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
</span><a href="#local-6989586621679547716"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; dec_state
forall a. FilePath -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;codec_state&quot;</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547705"><span class="hs-identifier hs-var">bbuf1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-910"></span><span>               </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
</span><a href="GHC.IO.Encoding.html#latin1_decode"><span class="hs-identifier hs-var">latin1_decode</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547705"><span class="hs-identifier hs-var">bbuf1</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547707"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-911"></span><span>          </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679547697"><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547697"><span class="hs-identifier hs-var">decoder</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-912"></span><span>               </span><span id="local-6989586621679547696"><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679547696"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state -&gt; IO dec_state
forall from to state. BufferCodec from to state -&gt; IO state
</span><a href="GHC.IO.Encoding.Types.html#getState"><span class="hs-identifier hs-var hs-var">getState</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547697"><span class="hs-identifier hs-var">decoder</span></a></span><span>
</span><span id="line-913"></span><span>               </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
-&gt; (dec_state, Buffer Word8) -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
</span><a href="#local-6989586621679547716"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679547696"><span class="hs-identifier hs-var">state</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547705"><span class="hs-identifier hs-var">bbuf1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-914"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextDecoder dec_state
-&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-var">streamEncode</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547697"><span class="hs-identifier hs-var">decoder</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547705"><span class="hs-identifier hs-var">bbuf1</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547707"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-915"></span><span>
</span><span id="line-916"></span><span>  </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readTextDevice after decoding: cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547699"><span class="hs-identifier hs-var">cbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span>
</span><span id="line-917"></span><span>        </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot; bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547700"><span class="hs-identifier hs-var">bbuf2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-918"></span><span>
</span><span id="line-919"></span><span>  </span><span class="hs-comment">-- We can't return from readTextDevice without reading at least a single extra character,</span><span>
</span><span id="line-920"></span><span>  </span><span class="hs-comment">-- so check that we have managed to achieve that</span><span>
</span><span id="line-921"></span><span>  </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547718"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547700"><span class="hs-identifier hs-var">bbuf2</span></a></span><span>
</span><span id="line-922"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547699"><span class="hs-identifier hs-var">cbuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547707"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-923"></span><span>     </span><span class="hs-comment">-- we need more bytes to make a Char. NB: bbuf2 may be empty (even though bbuf1 wasn't) when we</span><span>
</span><span id="line-924"></span><span>     </span><span class="hs-comment">-- are using an encoding that can skip bytes without outputting characters, such as UTF8//IGNORE</span><span>
</span><span id="line-925"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice%27"><span class="hs-identifier hs-var">readTextDevice'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547748"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547700"><span class="hs-identifier hs-var">bbuf2</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547707"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-926"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547699"><span class="hs-identifier hs-var">cbuf'</span></a></span><span>
</span><span id="line-927"></span><span>
</span><span id="line-928"></span><span class="hs-comment">-- we have an incomplete byte sequence at the end of the buffer: try to</span><span>
</span><span id="line-929"></span><span class="hs-comment">-- read more bytes.</span><span>
</span><span id="line-930"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#readTextDevice%27"><span class="hs-identifier hs-type">readTextDevice'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-931"></span><span id="readTextDevice%27"><span class="annot"><span class="annottext">readTextDevice' :: Handle__ -&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice%27"><span class="hs-identifier hs-var hs-var">readTextDevice'</span></a></span></span><span> </span><span id="local-6989586621679547693"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679547693"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547658"><span id="local-6989586621679547659"><span id="local-6989586621679547660"><span id="local-6989586621679547661"><span id="local-6989586621679547662"><span id="local-6989586621679547663"><span id="local-6989586621679547664"><span id="local-6989586621679547665"><span id="local-6989586621679547666"><span id="local-6989586621679547667"><span id="local-6989586621679547668"><span id="local-6989586621679547669"><span id="local-6989586621679547670"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547658"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679547657"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547657"><span class="hs-identifier hs-var">bbuf0</span></a></span></span><span> </span><span id="local-6989586621679547656"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547656"><span class="hs-identifier hs-var">cbuf0</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-932"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-933"></span><span>  </span><span class="hs-comment">-- copy the partial sequence to the beginning of the buffer, so we have</span><span>
</span><span id="line-934"></span><span>  </span><span class="hs-comment">-- room to read more bytes.</span><span>
</span><span id="line-935"></span><span>  </span><span id="local-6989586621679547655"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547655"><span class="hs-identifier hs-var">bbuf1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Buffer.html#slideContents"><span class="hs-identifier hs-var">slideContents</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547657"><span class="hs-identifier hs-var">bbuf0</span></a></span><span>
</span><span id="line-936"></span><span>
</span><span id="line-937"></span><span>  </span><span class="hs-comment">-- readTextDevice only calls us if we got some bytes but not some characters.</span><span>
</span><span id="line-938"></span><span>  </span><span class="hs-comment">-- This can't occur if haDecoder is Nothing because latin1_decode accepts all bytes.</span><span>
</span><span id="line-939"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679547653"><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547653"><span class="hs-identifier hs-var">decoder</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="#local-6989586621679547662"><span class="hs-identifier hs-var">haDecoder</span></a></span><span>
</span><span id="line-940"></span><span>
</span><span id="line-941"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679547652"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547652"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547651"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547651"><span class="hs-identifier hs-var">bbuf2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#fillReadBuffer"><span class="hs-identifier hs-var">Buffered.fillReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547670"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547655"><span class="hs-identifier hs-var">bbuf1</span></a></span><span>
</span><span id="line-942"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679547652"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-943"></span><span>   </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-944"></span><span>     </span><span class="hs-comment">-- bbuf2 can be empty here when we encounter an invalid byte sequence at the end of the input</span><span>
</span><span id="line-945"></span><span>     </span><span class="hs-comment">-- with a //IGNORE codec which consumes bytes without outputting characters</span><span>
</span><span id="line-946"></span><span>     </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547651"><span class="hs-identifier hs-var">bbuf2</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">IO (Buffer Char)
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier hs-var">ioe_EOF</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-947"></span><span>     </span><span class="hs-special">(</span><span id="local-6989586621679547650"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547650"><span class="hs-identifier hs-var">bbuf3</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679547649"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547649"><span class="hs-identifier hs-var">cbuf1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
-&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Encoding.Types.html#recover"><span class="hs-identifier hs-var hs-var">recover</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547653"><span class="hs-identifier hs-var">decoder</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547651"><span class="hs-identifier hs-var">bbuf2</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547656"><span class="hs-identifier hs-var">cbuf0</span></a></span><span>
</span><span id="line-948"></span><span>     </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readTextDevice' after recovery: bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547650"><span class="hs-identifier hs-var">bbuf3</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;, cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547649"><span class="hs-identifier hs-var">cbuf1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-949"></span><span>     </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547668"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547650"><span class="hs-identifier hs-var">bbuf3</span></a></span><span>
</span><span id="line-950"></span><span>     </span><span class="hs-comment">-- We should recursively invoke readTextDevice after recovery,</span><span>
</span><span id="line-951"></span><span>     </span><span class="hs-comment">-- if recovery did not add at least one new character to the buffer:</span><span>
</span><span id="line-952"></span><span>     </span><span class="hs-comment">--  1. If we were using IgnoreCodingFailure it might be the case that</span><span>
</span><span id="line-953"></span><span>     </span><span class="hs-comment">--     cbuf1 is the same length as cbuf0 and we need to raise ioe_EOF</span><span>
</span><span id="line-954"></span><span>     </span><span class="hs-comment">--  2. If we were using TransliterateCodingFailure we might have *mutated*</span><span>
</span><span id="line-955"></span><span>     </span><span class="hs-comment">--     the byte buffer without changing the pointers into either buffer.</span><span>
</span><span id="line-956"></span><span>     </span><span class="hs-comment">--     We need to try and decode it again - it might just go through this time.</span><span>
</span><span id="line-957"></span><span>     </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547649"><span class="hs-identifier hs-var">cbuf1</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547656"><span class="hs-identifier hs-var">cbuf0</span></a></span><span>
</span><span id="line-958"></span><span>      </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547693"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547649"><span class="hs-identifier hs-var">cbuf1</span></a></span><span>
</span><span id="line-959"></span><span>      </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547649"><span class="hs-identifier hs-var">cbuf1</span></a></span><span>
</span><span id="line-960"></span><span>   </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-961"></span><span>    </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readTextDevice' after reading: bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547651"><span class="hs-identifier hs-var">bbuf2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-962"></span><span>
</span><span id="line-963"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679547648"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547648"><span class="hs-identifier hs-var">bbuf3</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547647"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547647"><span class="hs-identifier hs-var">cbuf1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-964"></span><span>       </span><span id="local-6989586621679547646"><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679547646"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state -&gt; IO dec_state
forall from to state. BufferCodec from to state -&gt; IO state
</span><a href="GHC.IO.Encoding.Types.html#getState"><span class="hs-identifier hs-var hs-var">getState</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547653"><span class="hs-identifier hs-var">decoder</span></a></span><span>
</span><span id="line-965"></span><span>       </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
-&gt; (dec_state, Buffer Word8) -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
</span><a href="#local-6989586621679547666"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679547646"><span class="hs-identifier hs-var">state</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547651"><span class="hs-identifier hs-var">bbuf2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-966"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextDecoder dec_state
-&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-var">streamEncode</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547653"><span class="hs-identifier hs-var">decoder</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547651"><span class="hs-identifier hs-var">bbuf2</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547656"><span class="hs-identifier hs-var">cbuf0</span></a></span><span>
</span><span id="line-967"></span><span>
</span><span id="line-968"></span><span>    </span><span class="annot"><span class="annottext">FilePath -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;readTextDevice' after decoding: cbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547647"><span class="hs-identifier hs-var">cbuf1</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span>
</span><span id="line-969"></span><span>          </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot; bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">FilePath -&gt; FilePath -&gt; FilePath
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; FilePath
forall a. Buffer a -&gt; FilePath
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547648"><span class="hs-identifier hs-var">bbuf3</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-970"></span><span>
</span><span id="line-971"></span><span>    </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547668"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547648"><span class="hs-identifier hs-var">bbuf3</span></a></span><span>
</span><span id="line-972"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547656"><span class="hs-identifier hs-var">cbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547647"><span class="hs-identifier hs-var">cbuf1</span></a></span><span>
</span><span id="line-973"></span><span>       </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice%27"><span class="hs-identifier hs-var">readTextDevice'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547693"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547648"><span class="hs-identifier hs-var">bbuf3</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547647"><span class="hs-identifier hs-var">cbuf1</span></a></span><span>
</span><span id="line-974"></span><span>       </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547647"><span class="hs-identifier hs-var">cbuf1</span></a></span><span>
</span><span id="line-975"></span><span>
</span><span id="line-976"></span><span class="hs-comment">-- Read characters into the provided buffer.  Do not block;</span><span>
</span><span id="line-977"></span><span class="hs-comment">-- return zero characters instead.  Raises an exception on end-of-file.</span><span>
</span><span id="line-978"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#readTextDeviceNonBlocking"><span class="hs-identifier hs-type">readTextDeviceNonBlocking</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-979"></span><span id="readTextDeviceNonBlocking"><span class="annot"><span class="annottext">readTextDeviceNonBlocking :: Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDeviceNonBlocking"><span class="hs-identifier hs-var hs-var">readTextDeviceNonBlocking</span></a></span></span><span> </span><span id="local-6989586621679547645"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679547645"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547623"><span id="local-6989586621679547624"><span id="local-6989586621679547625"><span id="local-6989586621679547626"><span id="local-6989586621679547627"><span id="local-6989586621679547628"><span id="local-6989586621679547629"><span id="local-6989586621679547630"><span id="local-6989586621679547631"><span id="local-6989586621679547632"><span id="local-6989586621679547633"><span id="local-6989586621679547634"><span id="local-6989586621679547635"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547623"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679547622"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547622"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-980"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-981"></span><span>  </span><span id="local-6989586621679547621"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547621"><span class="hs-identifier hs-var">bbuf0</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547633"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-982"></span><span>  </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547621"><span class="hs-identifier hs-var">bbuf0</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-983"></span><span>     </span><span class="hs-special">(</span><span id="local-6989586621679547620"><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679547620"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547619"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547619"><span class="hs-identifier hs-var">bbuf1</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Maybe Int, Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Maybe Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#fillReadBuffer0"><span class="hs-identifier hs-var">Buffered.fillReadBuffer0</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679547635"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547621"><span class="hs-identifier hs-var">bbuf0</span></a></span><span>
</span><span id="line-984"></span><span>     </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Maybe Int -&gt; Bool
forall a. Maybe a -&gt; Bool
</span><a href="Data.Maybe.html#isNothing"><span class="hs-identifier hs-var">isNothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679547620"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">IO ()
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier hs-var">ioe_EOF</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-comment">-- raise EOF</span><span>
</span><span id="line-985"></span><span>     </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547633"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547619"><span class="hs-identifier hs-var">bbuf1</span></a></span><span>
</span><span id="line-986"></span><span>
</span><span id="line-987"></span><span>  </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#decodeByteBuf"><span class="hs-identifier hs-var">decodeByteBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679547645"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547622"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-988"></span><span>
</span><span id="line-989"></span><span class="hs-comment">-- Decode bytes from the byte buffer into the supplied CharBuffer.</span><span>
</span><span id="line-990"></span><span class="annot"><a href="GHC.IO.Handle.Internals.html#decodeByteBuf"><span class="hs-identifier hs-type">decodeByteBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-991"></span><span id="decodeByteBuf"><span class="annot"><span class="annottext">decodeByteBuf :: Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#decodeByteBuf"><span class="hs-identifier hs-var hs-var">decodeByteBuf</span></a></span></span><span> </span><span id="local-6989586621679547616"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679547616"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679547592"><span id="local-6989586621679547593"><span id="local-6989586621679547594"><span id="local-6989586621679547595"><span id="local-6989586621679547596"><span id="local-6989586621679547597"><span id="local-6989586621679547598"><span id="local-6989586621679547599"><span id="local-6989586621679547600"><span id="local-6989586621679547601"><span id="local-6989586621679547602"><span id="local-6989586621679547603"><span id="local-6989586621679547604"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679547592"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679547591"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547591"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-992"></span><span>  </span><span class="hs-comment">--</span><span>
</span><span id="line-993"></span><span>  </span><span id="local-6989586621679547590"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547590"><span class="hs-identifier hs-var">bbuf0</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547602"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-994"></span><span>
</span><span id="line-995"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679547589"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547589"><span class="hs-identifier hs-var">bbuf2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679547588"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547588"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-996"></span><span>      </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="#local-6989586621679547596"><span class="hs-identifier hs-var">haDecoder</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-997"></span><span>          </span><span class="annot"><span class="annottext">Maybe (TextDecoder dec_state)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-998"></span><span>               </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
-&gt; (dec_state, Buffer Word8) -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
</span><a href="#local-6989586621679547600"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">FilePath -&gt; dec_state
forall a. FilePath -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">FilePath
</span><span class="hs-string">&quot;codec_state&quot;</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547590"><span class="hs-identifier hs-var">bbuf0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-999"></span><span>               </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
</span><a href="GHC.IO.Encoding.html#latin1_decode"><span class="hs-identifier hs-var">latin1_decode</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547590"><span class="hs-identifier hs-var">bbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547591"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-1000"></span><span>          </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679547587"><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547587"><span class="hs-identifier hs-var">decoder</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1001"></span><span>               </span><span id="local-6989586621679547586"><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679547586"><span class="hs-identifier hs-var">state</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state -&gt; IO dec_state
forall from to state. BufferCodec from to state -&gt; IO state
</span><a href="GHC.IO.Encoding.Types.html#getState"><span class="hs-identifier hs-var hs-var">getState</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547587"><span class="hs-identifier hs-var">decoder</span></a></span><span>
</span><span id="line-1002"></span><span>               </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
-&gt; (dec_state, Buffer Word8) -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (dec_state, Buffer Word8)
</span><a href="#local-6989586621679547600"><span class="hs-identifier hs-var">haLastDecode</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">dec_state
</span><a href="#local-6989586621679547586"><span class="hs-identifier hs-var">state</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547590"><span class="hs-identifier hs-var">bbuf0</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1003"></span><span>               </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TextDecoder dec_state
-&gt; Buffer Word8 -&gt; Buffer Char -&gt; IO (Buffer Word8, Buffer Char)
forall from to state.
BufferCodec from to state
-&gt; Buffer from -&gt; Buffer to -&gt; IO (Buffer from, Buffer to)
</span><a href="GHC.IO.Handle.Internals.html#streamEncode"><span class="hs-identifier hs-var">streamEncode</span></a></span><span> </span><span class="annot"><span class="annottext">TextDecoder dec_state
</span><a href="#local-6989586621679547587"><span class="hs-identifier hs-var">decoder</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547590"><span class="hs-identifier hs-var">bbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547591"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-1004"></span><span>
</span><span id="line-1005"></span><span>  </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679547602"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679547589"><span class="hs-identifier hs-var">bbuf2</span></a></span><span>
</span><span id="line-1006"></span><span>  </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679547588"><span class="hs-identifier hs-var">cbuf'</span></a></span><span>
</span><span id="line-1007"></span><span>
</span><span id="line-1008"></span></pre></body></html>